Menu Close

Problem 3

My (very awful, but works) solution, in Python:

import math

print("What number's prime factors do you want to find")
theNum = int(input())
#theNum = 600851475143
def getFactors(num):
    factors = []
    for i in range(1, int(math.sqrt(num)) + 1):
        if (num % i == 0):
            factors.append(i)
            factors.append(num // i)
    return factors;

def isPrime(num):
    return len(getFactors(num)) == 2


primes = getFactors(theNum)
largest = 0
for i in primes:
    if (isPrime(i) and i > largest):
        largest = i
print(largest)