-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCarmichael_Numbers.py
More file actions
51 lines (38 loc) · 902 Bytes
/
Carmichael_Numbers.py
File metadata and controls
51 lines (38 loc) · 902 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
50
51
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
n = int(input())
# Write an action using print
# To debug: print >> sys.stderr, "Debug messages..."
def gcd(a, b):
if a < b:
return int(gcd(b, a))
if a % b == 0:
return b
return int(gcd(b, a % b))
def checkprime(p):
flag = True
for i in range(2, p):
if int(p % i) == 0:
flag = False
break
return flag
def icm(n):
if checkprime(n):
return 0
b = 2
while b < n:
# If "b" is relatively prime to n
if int(gcd(b, n)) == 1:
# And pow(b, n-1)% n is not 1,
# return false.
if int(pow(b, n - 1, n)) != 1:
return 0
b = b + 1
return 1
# print n
if icm(n):
print("YES")
else:
print("NO")