forked from wangjohn/mit-courses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sum_mod_p.py~
39 lines (31 loc) · 859 Bytes
/
sum_mod_p.py~
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
def getsum(k, p):
sum = 0
for i in xrange(1,p):
sum += i**k
sum = sum % p
return sum
def factorial(k):
if (k == 1):
return 1
else:
return k*factorial(k-1)
def modpsq(p):
return factorial(p-1) % p^2
def getprimes(stop):
output = []
for i in xrange(2, stop):
append = True
for j in xrange(2, i//2 + 1):
if i % j == 0:
append = False
if append:
output.append(i)
return output
def main1():
for prime in [2,3,5,7,11,13,17,19,23,29,31]:
print "Prime: ", prime
for i in xrange(prime):
print i, "Sum: ", getsum(i,prime)
if __name__ == '__main__':
for prime in getprimes(50):
print "Prime: ", prime, "Factorial mod psquared: ", modpsq(prime)