Array ( [0] => [1] => questions [2] => Basic [3] => Jumble-With-Numbers ) Codevita Previous Questions | Jumble With Numbers | THE INQUISITIVE





Jumble With Numbers

LEVEL:Beginner

Description

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:
A Mathew number is computed as follows using the formula:
H(n) = n(2n-1),br> And scientist John invented another number which is built by the following formula which is called John number.
T(n) = n(n+1)/2
Now Mathew and John are jumbled while combining their work. Now help them combine their research work by finding out number in a given range that satisfies both properties. Using the above formula, the first few Mathew-John numbers are:
1 6 15 28

Input Format

Input consists of 3 integers T1,T2,M separated by space . T1 and T2 are upper and lower limits of the range. The range is inclusive of both T1 and T2. Find Mth number in range [T1,T2] which is actually a Mathew-John number.
Constraints:
0 < T1 < T2 < 1000000
Print Mth number from formed sequence between T1 and T2(inclusive)

Output Format

Find Mth number in range [T1,T2] which is actually a Mathew-John number.


Example 1:

Input
90 150 2
Output
120
Example 2:

Input
10 20 1
Output
15
Example 3:

Input
10 100 3
Output
45

oops

Login to see Discussion




Approach

If we analyse the problem, we can know that every Mathew s number is a John number.
n(2n-1) can be converted into a quadratic equation. Then when we apply the formula for roots of quadratic equation.
The value of n can be obtained from the equation.
Now return (n+m)*(2*(n+m)-1) .


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution