Hi all,
Im having a bit of a problem with PON spoj.pl/problems/PON/
Admittedly I am new to python, but my code works locally, however I get a NZEC error for my code which works locally, ie:
C:\Documents and Settings\teepee\My Documents\python>python 288PON.py
5
2
3
4
5
6
YES
YES
NO
YES
NO
It is likely that it is the way the input is formatted perhaps or the way i formay my output ? I did the Test and the Crypt1 before, with no issues. Any hints ?
import random, sys
def miller_rabin_pass(a, n):
d = n - 1
s = 0
while d % 2 == 0:
d >>= 1
s += 1
a_to_power = pow(a, d, n)
if a_to_power == 1:
return True
for i in xrange(s-1):
if a_to_power == n - 1:
return True
a_to_power = (a_to_power * a_to_power) % n
return a_to_power == n - 1
def miller_rabin(n):
for repeat in xrange(20):
a = 0
while a == 0:
a = random.randrange(n)
if not miller_rabin_pass(a, n):
return False
return True
input = []
data = raw_input().strip()
while data != '':
input.append(data)
data = raw_input().strip()
for x in input:
if int(x) != 2:
print (miller_rabin(int(x)) and "YES" or "NO")
else:
pass