assuming this is a very, very beginning exercise, let us not say this is a really poorly defined problem, but rather an exorcise that can be later be used to optimize - i.e.: when arrays or data structures are added.
First, let us talk about prime numbers: after you start with 2 you don't need to check any of the other even numbers. so we generate 2 then we start with 3,5,7,9,...
Second, we know that after 3 all primes candidates will fall into 6n +- 1.
so we check for 2, then 3, then in a loop we check 5 and 7, then we check 11 and 13, .... note not all of these candidates are prime, but if it is prime it will be within the candidates.
Also for n - we only need to check up to square root of 10,000.