Given x(<=1000) and y(<=1000), find the smallest z(>0) such that (x+y+z) is prime.
Keep increasing i (starting from 1) until (x+y+i) is not prime. i will never exceed 40 since x+y <= 2000. So we can afford to check each number one by one.
To check if a number N is prime:
def check_prime(N): for i=2 to sqrt(N): if N%i==0: return false return true
Alternatively, we can use sieve of eratosthenes to check primes.
Naive primality testing (checking if N is divisible by any number from 2 to N-1) could also pass if precomputation is done.
AUTHOR’S AND TESTER’S SOLUTIONS:
To be updated soon.