-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtopian Tree
More file actions
49 lines (31 loc) · 703 Bytes
/
Utopian Tree
File metadata and controls
49 lines (31 loc) · 703 Bytes
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
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the utopianTree function below.
def utopianTree(n):
a=2
period=[]
for i in range(2,n+1):
period.append(i)
if n >= 2:
for j in range(0,len(period)):
if period[j] % 2 == 0:
a=a+1
else:
a=a*2
return a
elif n == 1:
return 2
elif n == 0:
return 1
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
for t_itr in range(t):
n = int(input())
result = utopianTree(n)
fptr.write(str(result) + '\n')
fptr.close()