Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import math
- def expFinder(a,x,p):
- if x == 1:
- return a
- else:
- if x % 2 == 0:
- return expFinder(a*a%p,x/2,p) % p
- else:
- return a*expFinder(a*a % p, (x-1)/2,p) % p
- def isPrime(a):
- if a == 1:
- return 0
- x = int(math.ceil(math.sqrt(a)))
- for i in range(2,x+1):
- if a % i == 0:
- return 0
- return 1
- L = []
- N = sys.stdin.readline()
- N = N.split()
- p = int(N[0])
- a = int(N[1])
- while(p != 0 and a != 0):
- if isPrime(p) == 1:
- L.append(0)
- else:
- if expFinder(a,p,p) == a:
- L.append(1)
- else:
- L.append(0)
- N = sys.stdin.readline()
- N = N.split()
- p = int(N[0])
- a = int(N[1])
- for i in L:
- if i == 0:
- print "no"
- else:
- print "yes"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement