Ejemplo n.º 1
0
def goldbach(n):
    result = []
    primes_list = []
    for number in range(2, n // 2 + 1):
        if is_prime(number) and is_prime(n - number):
            result.append((number, n - number))
    return result
Ejemplo n.º 2
0
def goldbach(n):
    result = []
    primes_list = []
    for number in range(2, n // 2 + 1):
        if is_prime(number) and is_prime(n - number):
            result.append((number, n - number))
    return result
def prime_number_of_divisors(n):
	number_of_divisors = 0
	for i in range(1, n + 1, 1):
		if n % i == 0:
			number_of_divisors += 1
	print(number_of_divisors)

	if is_prime(number_of_divisors):
		return True
	else:
		return False
def prime_factorization(n):
    result = []
    while n > 1:
        for index in range(2, n+1):
            if is_prime(index):
                counter = 0
                while n % index == 0:
                    counter += 1
                    n = n / index
                    if counter > 1:
                        result.append((index, counter + 1))
    return result
def prime_factorization(n):
    result = []
    while n > 1:
        for index in range(2, n + 1):
            if is_prime(index):
                counter = 0
                while n % index == 0:
                    counter += 1
                    n = n / index
                    if counter > 1:
                        result.append((index, counter + 1))
    return result
Ejemplo n.º 6
0
def test_is_not_prime():
    assert prime_number.is_prime(3556) == 'NO'
Ejemplo n.º 7
0
def test_is_prime():
    assert prime_number.is_prime(3557) == 'YES'
 def test_is_prime_ok(self):
     for i in [2, 3, 5, 7, 11, 13, 17, 19]:
         self.assertTrue(is_prime(i))
 def test_is_prime_raise_typeerror(self):
     with self.assertRaises(TypeError):
         is_prime('string')
 def test_is_prime_negative(self):
     self.assertFalse(is_prime(-1))
 def test_is_prime_no(self):
     for i in [1, 4, 6, 8, 9, 10, 14, 15, 16, 18, 20]:
         self.assertFalse(is_prime(i))
Ejemplo n.º 12
0
array = []
dec_to_base_recursive.change_base(number=10, base=2, callback=array)
""" NUMERIC OPTIMISATION """

gcd_iterative.gcd(a=5, b=10)

gcd_recursive.gcd(a=5, b=10)

lcm_iterative.lcm(a=5, b=10)

lcm_recursive.lcm(a=5, b=10)

prime_factorisation.factorise(number=100)

change_making.change(amount=6)

exponentiation_by_squaring.exponentiate(base=2, power=10)
""" SEQUENCES """

fibonacci_iterative.fibonacci(count=5)

fibonacci_recursive.fibonacci(count=5)

sieve_of_eratosthenes.sieve(limit=13)
""" NUMBER THEORY """

prime_number.is_prime(number=13)

perfect_number.is_perfect(number=6)
Ejemplo n.º 13
0
 def test_numbers(self):
     a = 11
     result = prime_number.is_prime(a)
     self.assertEqual(result, sympy.isprime(11))