3

I'm working on this code to calculate Fermat's Little Theorem and it works as it should. The only issue that I have is that I would hope for it to be more efficient. Is there a way to limit the print to only true congruences?

for i in range (1,351):
    print i, [(2 << i - 2) % i == 1]
Vaibhav Vishal
  • 6,576
  • 7
  • 27
  • 48

1 Answers1

1

This code doesn't even works for me, it gives an error: ValueError: negative shift count. But considering it's working for you somehow, you can use an if condition to print only when true:

for i in range (2,351):  # changing 1 to 2 fixed the error for me.
    if (2 << i-2) % i == 1:  # this will check if it's true, then only print
        print i, [(2 << i - 2) % i == 1]
Vaibhav Vishal
  • 6,576
  • 7
  • 27
  • 48