int i, j;
for(i=2; i<16; i++) {
for(j=2; j<=(i/j); j++) // j ranges from 2 up to square root of i. this is because the program is testing for divisors of i.
if(!(i%j)) break ; // if j divides i then stop
if(j>(i/j)) cout<<i<<" / "<<j<<endl; // if the condition of the for loop has been broken (i.e. the loop completed without the break) then output. The loop would only get this far if i was prime
}
If N has exactly two factors A and B, A <= B, it is easy to see that A must be no more than sqrt( N ), since
if that were not true, then A * B must be greater than N.
If N has more than two factors A1 <= A2 <= ... An, then
it also follows that the smallest of these factors, A1, must also be less than or equal to
sqrt( N ), since otherwise A1 * A2 * ... * An must be strictly
greater than N.
Therefore, one can write an algorithm that brute force checks all values <= sqrt( N ) and be
ensured that the algorithm will find all factors of N.