Lecture Notes on 21 Mar 2014 # get greatest common divisor of two numbers def gcd (a, b): while (a != b): if (a > b): a = a - b else: b = b - a return a # get the least common multiple of two numbers def lcm (a, b): return (a * b) // gcd (a, b) # product of the digits of a number def prod_digits (n): product = 1 while (n > 0): product = product * (n % 10) n = n // 10 if (product == 0): break return product # determine if a number is prime def is_prime (n): limit = int (n ** 0.5) + 1 for div in range (2, limit): if (n % div == 0): return False return True def main(): # determine the least common multiple of the first 20 numbers multiple = 1 for i in range (2, 21): multiple = lcm (multiple, i) print (multiple) # difference between sum of the squares and square of the sum sum_k = 0 sum_k2 = 0 for k in range (1, 101): sum_k += k sum_k2 += k * k print (sum_k * sum_k - sum_k2) # find the 10001st prime num_prime = 0 counter = 1 while (num_prime < 10001): counter += 1 if (is_prime(counter)): num_prime += 1 print (counter) # find the largest product of 5 digits max_prod = 0 max_digits = 0 num = 7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450 while (num > 9999): n = num % 100000 prod = prod_digits (n) if (prod > max_prod): max_prod = prod max_digits = n num = num // 10 print (max_digits, max_prod) main()