Skip to content

Instantly share code, notes, and snippets.

@unaoya
Last active December 19, 2017 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unaoya/11cae6e6ba81db7b5d04b937febca4d2 to your computer and use it in GitHub Desktop.
Save unaoya/11cae6e6ba81db7b5d04b937febca4d2 to your computer and use it in GitHub Desktop.
def issol(x,y,z,p,k):
return (pow(x,k,p) + pow(y,k,p)) % p == pow(z,k,p)
def count(p,k):
c = 0
for x in range(1,p):
for y in range(1,p):
for z in range(1,p):
if issol(x,y,z,p,k):
c += 1
return c
import math
def primes(n):
result = set(range(2,n))
for i in range(2,math.floor(math.sqrt(n))):
for j in range(2,n//i):
result.discard(i*j)
return result
k=4
for p in primes(100):
print('%d : %d' % (p, count(p,k)))
import math
def primes(n):
result = set(range(2,n))
for i in range(2,math.floor(math.sqrt(n))+1):
for j in range(2,n//i+1):
result.discard(i*j)
return result
import numpy as np
k = 6
n = 500
w = np.power(np.arange(1,n),k)
for p in primes(n):
x = w[:p-1] % p
print('%d : %d' % (p, (((((x + x.reshape((p-1,1))) - x.reshape(p-1,1,1)) % p==0).sum()))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment