-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathNG0FRCTN-6421944-src.cpp
More file actions
53 lines (46 loc) · 1.15 KB
/
NG0FRCTN-6421944-src.cpp
File metadata and controls
53 lines (46 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#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;
if(number == 1)
{
printf("%d/%d\n", 1, 1);
continue;
}
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;
}