## Editorial for CCC '19 S2 - Pretty Average Primes

**only**when stuck, and

**not to copy-paste code from it**. Please be respectful to the problem author and editorialist.

**Submitting an official solution before solving the problem yourself is a bannable offence.**

Author:

For this problem, we can use a simple for-loop to generate values of and .

Set and . Loop through the integers from to .

Check if they are both prime and that is equal to .

Recall that an integer is prime if it is greater than 1 and cannot be formed by multiplying two smaller natural numbers.

For subtask 1, it is sufficient to loop through the integers from to when checking if the integer is prime. If is divisible by any of the values from to , the integer is not prime.

This gives us an algorithm.

For subtask 2, an optimization is made. Loop through the integers from to . If is divisible by any of the values from to , the integer is not prime. The for-loop now has a time complexity of instead of .

This gives us an algorithm.

## Comments