Exemple #1
0
def get_prime_factors(val):
	prime_factors = []
	d = val
	factor = 2
	while factor <= d:
		if is_prime(factor):
			while d % factor == 0:
				d //= factor
				prime_factors.append(factor)
		factor += 1
	return sorted(prime_factors)
Exemple #2
0
from prime_utils import is_prime

#start counting prime numbers until N is found
counter = 1;
x = 3
while True:
  if is_prime(x):
    counter += 1
    if counter == 10001:
      print x
      exit()
  x += 2
Exemple #3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

sys.path.append('../../utils')

from prime_utils import is_prime

"""
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?
"""

count = 0
max_count = 10001
num = 2

while count < max_count:
    if is_prime(num):
        count += 1
        if count == max_count:
            print num
    num += 1
 def test_is_prime_returns_false_for_negative_composite(self):
     n = -1234321  #  1234321 = 1111 * 1111
     result = prime_utils.is_prime(n)
     self.assertFalse(result)
 def test_is_prime_returns_false_for_zero(self):
     n = 0
     result = prime_utils.is_prime(n)
     self.assertFalse(result)
 def test_is_prime_returns_true_for_negative_prime(self):
     n = -101
     result = prime_utils.is_prime(n)
     self.assertTrue(result)
 def test_is_prime_returns_true_for_prime_number(self):
     n = 101
     result = prime_utils.is_prime(n)
     self.assertTrue(result)
 def test_is_prime_returns_false_for_second_composite(self):
     n = 144
     result = prime_utils.is_prime(n)
     self.assertFalse(result)
 def test_is_prime_returns_true_for_two(self):
     n = 2
     result = prime_utils.is_prime(n)
     self.assertTrue(result)
Exemple #10
0
from prime_utils import is_prime

#start counting prime numbers until N is found
counter = 1
x = 3
while True:
    if is_prime(x):
        counter += 1
        if counter == 10001:
            print x
            exit()
    x += 2