Project Euler 347 - Largest integer divisible by two primes

Official link: https://projecteuler.net/problem=347

Thought Process

The largest prime possible we need is p = 10,000,000/2 because we can have 2*p as our 2 distinct primes.

  1. Create a list of all primes, called p, less than 10,000,000/2

  2. Create a double nested loop with variables x and y, where x goes from 1 to len(p), y goes from x+1 to len(p)

    1. We now have p[x]*p[y], we check if that is less than 10,000,000 to continue

    2. Then we want to find the maximum number containing these 2 factors, that is find a, b, such that p[x]^a * p[y]*b is maximised and less than 10,000,000, we can make another double loop for a and b

      1. where a can be between 1 and log(10,000,000/p[y], p[x])

      2. and b can be between 1 and log(10,000,000/p[x], p[y])

      3. Simply find the maximum and add that maximum to a total

Interactive Code

Enter an integer (yourinput)

Code will output S(yourinput)