Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 71 Online
OpenStudy (anonymous):

Im trying to use Fermat's little theorem at first assignment but it doesnt work somehow i realy need some help!

OpenStudy (anonymous):

primes=[] n = 0 for p in range (2,150000): if n < 1000: if (2**p-2) % p == 0: primes.append(p) n = len (primes) print primes

OpenStudy (anonymous):

I tried this formula to start with but i get 7741 as the final prime number why its not right?

OpenStudy (anonymous):

This is a cool approach I haven't seen before. I didn't know what Fermat's Little Theorem was, but from http://en.wikipedia.org/wiki/Fermat_primality_test, it appears that you're probably also finding Carmichael numbers: http://en.wikipedia.org/wiki/Carmichael_number

OpenStudy (anonymous):

I cant find a solution to exclude them so i will need to find another way i think :/.Thank you for reply!!

OpenStudy (anonymous):

bugrakokalp: When I ran your code, I found there are at least 18 different numbers in your list that are not prime. ex. 341 in your list has 11 and 31 as factors, and hence is not prime. I hope this helps.

OpenStudy (anonymous):

This code overlooks the fact that Fermat's primality test is only probabilistic-- http://en.wikipedia.org/wiki/Fermat_primality_test

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Aliciaa: finally done for @Ylynnaaa_120
34 minutes ago 8 Replies 2 Medals
Aliciaa: finally done!!! for Ylynnaaa_120
37 minutes ago 0 Replies 0 Medals
Ylynnaa: I drew my auntie) this was 3 weeks agoud83dudc80ud83dudc80
25 minutes ago 25 Replies 6 Medals
Ylynnaa: A art i made 3 weeks ago
52 minutes ago 0 Replies 0 Medals
Aliciaa: Collage request: Harriet Tubman for: @KarmaXD
53 minutes ago 15 Replies 2 Medals
vizer: Can someone explain to me why i feel so empty?
1 hour ago 8 Replies 0 Medals
Cheyyy: Love hurts. Why does love hurt si much
32 minutes ago 19 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!