forked from adityabisoi/ds-algo-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.cpp
46 lines (34 loc) · 876 Bytes
/
solution.cpp
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
#include <bits/stdc++.h>
using namespace std;
// Implementation Part
int utopianTree(int n) {
// Intialize for starting period , height = 1
// on observing pattern, and from problem statement
// concluded that, for
int r = 1;
for (int i = 1; i <= n; i++) {
// for even period height ----> height + 1
// for odd period height ----> height * 2;
if (i % 2 == 0)
r++;
else
r = r * 2;
}
return r;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
int t;
cin >> t;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
for (int t_itr = 0; t_itr < t; t_itr++) {
int n;
cin >> n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int result = utopianTree(n);
fout << result << "\n";
}
fout.close();
return 0;
}