Exemple #1
0
def givePrimeAt(index=100001):  #// my first simple algorithm
    if (index < 1 or isinstance(index, float)):
        return -1
    if index == 1:
        return 2
    prime_numbers = [2, 3]
    i = 1
    while len(prime_numbers) < index:
        prime_number = giveNextPrimeAt(i)
        isPrime(prime_number) and prime_numbers.append(prime_number)
        i += 1
    return prime_numbers[index - 1]
Exemple #2
0
def getNthPrime(N=100001):  #//another as efficient as above
    if N == 1:
        return 2
    index, primeNumber = 1, 3
    while index < N:
        if isPrime(primeNumber):
            index += 1
        primeNumber += 2
    return primeNumber - 2
Exemple #3
0
 def test_isPrime_returns_False_for_any_even_number_greater_than_2(self):
     self.assertFalse(isPrime(4))
     self.assertFalse(isPrime(100))
     self.assertFalse(isPrime(12345678908))
Exemple #4
0
 def test_isPrime_returns_True_for_2(self):
     self.assertTrue(isPrime(2))
Exemple #5
0
 def test_isPrime_returns_True_for_prime_number(self):
     self.assertTrue(isPrime(3))
     self.assertTrue(isPrime(103))
     self.assertTrue(isPrime(6857))
Exemple #6
0
 def test_isPrime_returns_False_for_35_and_81(self):
     self.assertFalse(isPrime(35))
     self.assertFalse(isPrime(81))
Exemple #7
0
 def test_isPrime_returns_True_for_104743(self):
     self.assertTrue(isPrime(104743))
Exemple #8
0
 def test_isPrime_returns_False_for_negative_number(self):
     self.assertFalse(isPrime(-1))
Exemple #9
0
 def test_isPrime_returns_False_for_1(self):
     self.assertFalse(isPrime(1))