https://github.com/skyv26/modified-kaprekar-number
In mathematics, a Kaprekar number for a given base is a non-negative integer, the representation of whose square in that base can be split into two parts that add up to the original number again. For instance, 45 is a Kaprekar number, because 45² = 2025 and 20+25 = 45.
https://github.com/skyv26/modified-kaprekar-number
Last synced: about 2 months ago
JSON representation
In mathematics, a Kaprekar number for a given base is a non-negative integer, the representation of whose square in that base can be split into two parts that add up to the original number again. For instance, 45 is a Kaprekar number, because 45² = 2025 and 20+25 = 45.
- Host: GitHub
- URL: https://github.com/skyv26/modified-kaprekar-number
- Owner: skyv26
- Created: 2022-09-13T08:15:57.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-13T08:23:58.000Z (over 2 years ago)
- Last Synced: 2025-01-19T04:55:51.699Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.95 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Modified-Kaprekar-Number
> In mathematics, a Kaprekar number for a given base is a non-negative integer, the representation of whose square in that base can be split into two parts that add up to the original number again. For instance, 45 is a Kaprekar number, because 45² = 2025 and 20+25 = 45.
## Explanation
A modified Kaprekar number is a positive whole number with a special property. If you square it, then split the number into two integers and sum those integers, you have the same value you started with.
Consider a positive whole number with digits. We square to arrive at a number that is either digits long or digits long. Split the string representation of the square into two parts, and . The right hand part, must be digits long. The left is the remaining substring. Convert those two substrings back to integers, add them and see if you get .
Function Description
Complete the kaprekarNumbers function in the editor below.
**kaprekarNumbers has the following parameter(s):**
- int p: the lower limit
- int q: the upper limit**Prints**
It should print the list of modified Kaprekar numbers, space-separated on one line and in ascending order. If no modified Kaprekar numbers exist in the given range, print `INVALID RANGE`. No return value is required.
**Input Format**
The first line contains the lower integer limit *p*.
The second line contains the upper integer limit *q*.**Note:** Your range should be inclusive of the limits.