![]() ![]() isprime = False test = test + 1 if isprime : # We add each prime to the primes list. ![]() if ( possibility % test ) = 0 : # This ends the while loop causing the next number # to be tested. isprime = True test = 2 while test < possibility and isprime : # Here we verify that the number is in fact prime by # starting at 2 and dividing it by every number lower # than the potential prime. # See Python Programming/Basic Math for more info. list = range ( 2, user ) # 0 and 1 are not prime, but our algorithm registers them # as prime, so we start with two for possibility in list : if (( 2 ** possibility ) - 2 ) % possibility = 0 : # Our algorithm (Fermat's little theorem) states # that if "i" is an integer and i^p-i divides evenly # into p, p is prime. user = 1 + int ( raw_input ( "What number would you like to count primes up to? " )) # 1 is added on to the user's number so that their number # is counted. ![]() Primes = # Creates a list that we will throw our prime numbers into. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |