We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f55fe6e commit 6077047Copy full SHA for 6077047
💍 P5/28474.py
@@ -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
16
+ factor[n] += 1
17
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
33
+ res = totient(n) + totient(n//2)
34
+ print(res)
0 commit comments