#include <stdio.h>
#include <math.h>
int main()
{
while(1)
{
long long int number;
scanf("%lld", &number);
if(number == 0)
break;
int level = log(number)/ log(2); //calculating the level in tree
long long int path[50];
int count = 0;
while(1) //storing the path toward root
{
if(count)
{
path[count] = path[count -1] /2;
if(path[count] == 1)
break;
}
else
path[count] = number;
count++;
}
int i, n = 1, d = 1;
for(i = count-1; i >= 0; i--) //traversing the path and caluclating accordingly
{
if((path[i]/2)*2 == path[i]) //even
{
d = n+d;
}
else //odd
{
n = n+d;
}
}
printf("%d/%d\n", n, d);
}
return 0;
}
putting the code properly, thanx i did not know that.
Well, it passed cases for me here.
Input:
1
2
3
7
32432
543543
5435
1000000000
10000000000
0
Output:
1/1
1/2
2/1
3/1
53/232
3118/841
255/92
7623/73411
7271/77695