Attempting to solve this problem:
For a positive number n, define S(n) as the sum of the integers x, for which
1 < x < n
andx^3 ≡ 1 mod n
.When
n=91
, there are 8 possible values for x, namely : 9, 16, 22, 29, 53, 74, 79, 81. Thus,S(91)=9+16+22+29+53+74+79+81=363
.Find S(13082761331670030).
Of course, my code works for S(91)
and when attempting to find S(13082761331670030)
I get two different errors.
Here is my code:
def modcube(n):
results = []
for k in range(1,n):
if k**3%n==1:
results.append(k)
return results
This produces Overflow error: range has too many items.
When I try using 'xrange' instead of 'range' I get an error stating python int too large to convert to c long. I have also just tried several other things without success.
Can anyone point me in the right direction, without telling me exactly how to solve it?
No spoilers please. I've been at it for two days, my next option is to try implementing this in Java since I'm new to Python.