#!/usr/bin/python3 """ Problem 3 - Largest prime factor The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? """ from modules.matlib import primeFactors print(max(primeFactors(600851475143))) # output largest number from list of prime factors of number
from modules.matlib import primeFactors factors = [] for x in range(2, 21, 1): facts = primeFactors(x) for f in facts: for i in range(facts.count(f)-factors.count(f)): factors.append(f) nsn = 1 for x in factors: nsn *= x print(nsn)
from modules.matlib import primeFactors print(max(primeFactors(600851475143)))
#!/usr/bin/python3 """ Problem 5 - Smallest multiple 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? """ from modules.matlib import primeFactors factors = [] # store factors for x in range(2, 21, 1): # for numbers from 2 to 20 facts = primeFactors(x) # list prime factors of x for f in facts: # each prime factors of x for i in range(facts.count(f) - factors.count(f)): factors.append(f) # append as many factors as this number has nsn = 1 # smallest multiple for x in factors: nsn *= x # multiply all factors print(nsn) # output result