Skip to content

Commit 6077047

Browse files
committed
💍 P5-28474
1 parent f55fe6e commit 6077047

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

💍 P5/28474.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
t = int(input())
2+
3+
def totient(n):
4+
factor = {}
5+
while n != 1:
6+
for i in range(2, int(n**0.5)+1):
7+
if n % i == 0:
8+
n //= i
9+
try:
10+
factor[i] += 1
11+
except:
12+
factor[i] = 1
13+
break
14+
else:
15+
try:
16+
factor[n] += 1
17+
except:
18+
factor[n] = 1
19+
n = 1
20+
res = 1
21+
for i in factor.keys():
22+
n *= i**factor[i]
23+
res *= i**factor[i] - i**(factor[i]-1)
24+
if not factor:
25+
res = 0
26+
return res
27+
28+
for _ in range(t):
29+
n = int(input())
30+
if n & 1:
31+
res = totient(n)
32+
else:
33+
res = totient(n) + totient(n//2)
34+
print(res)

0 commit comments

Comments
 (0)