combine their research work by finding out number in a given range that
satisfies both properties [on hold]
In NASA, two researchers, Mathew and John, started their work on a new
planet, but while practicing research they faced a mathematical
difficulty. In order to save the time they divided their work.
So scientist Mathew worked on a piece and invented a number computed with
the following formula:
T(n) = n(n+1)/2
These numbers are called Mathew numbers.
And scientist John invented another number which is built by adding the
squares of its digits. Doing this perpetually, the numbers will end in 1
or 4. If a positive integer ends with 1, then it is called John number.
Example of John numbers is:
13 = 1^2 + 3^2 = 1+9 = 10 (Step : 1).
10 = 1^2 + 0^2 = 1+0 = 1 (Step : 2), iteration ends in Step 2 since
number ends with 1.
Help Mathew and John combine their research work by finding out number in
a given range that satisfies both properties.
Input Format:
Input consists of 3 integers X, Y, N, one on each line. X and Y are upper
and lower limits of the range. The range is inclusive of both X and Y.
Find the Nth number in the range [X,Y] which is actually a Mathew-John.
Line 1
X, where X is the upper limit of the range
Line 2
Y, where Y is the lower limit of the range
Line 3
N, where the Nth element of the series is required
Output Format:
Output will show the Nth element of the Mathew-John series lying in the
range between X and Y.
Line 1
For valid input, print U, where U is the Nth element of the Mathew-John
series lying in the range between X and Y or No number is present at this
index. For invalid input, print Invalid Input.
Sample Test Cases:
SNo. Input Output
1
1
15
2
10
2
9
45
3
No number is present at this index
3
-5
@
4
Invalid Input
No comments:
Post a Comment