File tree 1 file changed +58
-0
lines changed 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ using namespace std ;
3
+
4
+ long long totalLength[51 ];
5
+ long long pattyLength[51 ];
6
+
7
+ void getLength (int level) {
8
+ if (level == 0 )
9
+ {
10
+ totalLength[level] = 1 ;
11
+ pattyLength[level] = 1 ;
12
+ return ;
13
+ }
14
+
15
+ getLength (level - 1 );
16
+
17
+ totalLength[level] = totalLength[level - 1 ] * 2 + 3 ;
18
+ pattyLength[level] = pattyLength[level - 1 ] * 2 + 1 ;
19
+ }
20
+
21
+ long long solve (int level, long long x) {
22
+ if (level == 0 )
23
+ {
24
+ return 1 ;
25
+ }
26
+
27
+ if (x <= 1 )
28
+ {
29
+ return 0 ;
30
+ }
31
+ else if (x <= 1 + totalLength[level - 1 ])
32
+ {
33
+ return solve (level - 1 , x - 1 );
34
+ }
35
+ else if (x == 1 + totalLength[level - 1 ] + 1 )
36
+ {
37
+ return pattyLength[level - 1 ] + 1 ;
38
+ }
39
+ else if (x < totalLength[level])
40
+ {
41
+ return pattyLength[level - 1 ] + 1 + solve (level - 1 , x - totalLength[level - 1 ] - 2 );
42
+ }
43
+ else
44
+ {
45
+ return pattyLength[level];
46
+ }
47
+ }
48
+
49
+ int main () {
50
+ int n;
51
+ long long x;
52
+
53
+ cin >> n >> x;
54
+
55
+ getLength (n);
56
+
57
+ cout << solve (n, x) << endl;
58
+ }
You can’t perform that action at this time.
0 commit comments