Ejemplo n.º 1
0
 def testGetFactorization(self):
     self.assertEqual([], getFactorization(1))
     self.assertEqual([[2, 1]], getFactorization(2))
     self.assertEqual([[2, 1], [5, 2]], getFactorization(50))
     
     self.assertRaises(AssertionError, getFactorization, 0)
     self.assertRaises(AssertionError, getFactorization, 0.5)
Ejemplo n.º 2
0
def phi(n):
	result = n
	if isPrime(n):
		return n - 1
	for p in getFactorization(n):
		result *= (1 - 1 / p[0])
	return result	
Ejemplo n.º 3
0
def phi(n):
	result = n
	for p in getFactorization(n):
		result *= (1 - 1 / p[0])
	return result		
Ejemplo n.º 4
0
 def testGetFactorizationOfToBigNumber(self):
     with self.assertRaises(Exception):
         getFactorization(15485867)  # 1.000.001th prime
Ejemplo n.º 5
0
 def testGetFactorization50(self):
     factorization = getFactorization(50)
     for factor in [[2, 1], [3, 0], [5, 2]]:
         self.assertIn(factor, factorization)
Ejemplo n.º 6
0
'''

The first two consecutive numbers to have two distinct prime factors are: 
14 = 2 × 7 and 15 = 3 × 5 

The first three consecutive numbers to have three distinct prime factors are: 
644 = 2² × 7 × 23 and 645 = 3 × 5 × 43 and 646 = 2 × 17 × 19. 

Find the first four consecutive integers to have four distinct prime factors. 
What is the first of these numbers? 
'''
from utilities.divisors import getFactorization

if __name__ == '__main__':
	facs = {}
	for i in range(125125, 1000000):
		facs.setdefault(i, getFactorization(i))
		if len(facs[i]) == 4:
			print(i, facs[i])
		for n in range(i, i + 4):
			facs.setdefault(n, getFactorization(n))
		if(all([len(facs[n]) == 4 for n in range(i, i + 4)])):
			print("solution: %d" % i)
			break
		
			
# 	print([i for i in range(1000000) if all([len(getFactorization(n)) == 4 for n in range(i, i + 4)])])
# 	print(getFactorization(644))