880 - Cantor Fractions


Difficulty : easy

Solution Description :

Math problem

When you expand the sires then you go
1/1, 2/1, 1/2, 3/1, 2/2, 1/3, 4/1, 3/2, 2/3, 1/4,.....

Upper part.: 1,| 2, 1,| 3, 2, 1,| 4, 3, 2, 1|
------------------------------------------------------------
Down  part: 1,| 1, 2,| 1, 2, 3,| 1, 2, 3, 4|
------------------------------------------------------------
Sires No   : 1,| 2, 3,| 4, 5, 6,| 7, 8, 9,10|
-------------------------------------------------------------

so see this part1:(1), part2:(1,2) part3:(1,2,3) part4:(1,2,3,4)....
so, you can write this 1+2+3+4...... = n(n+1)/2
first you need to find n=?

if input y then n(n+1)/2 = y => n^2+n-2y=0
using quadratic equation you find n =ceil(( -1 + ceil(sqrt(1+8y)))/2) 
here n = part no

if y=8 then n=4 i.e. Sires No 8 contain in part4
Now calculate the upper bound = n*(n+1)/2 for n=4 , upper bound=10

Suppose you need to print up/down
now, up = (upper bound - y)+1
        down = (n - up) + 1

You can use long data type in c for all calculation