If j
is equal to sqrt(i)
it might also be a valid factor, not only if it's smaller.
To iterate up to and including sqrt(i)
in your inner loop, you could write:
for (int j=2; j*j<=i; j++)
(Compared to using sqrt(i)
this has the advantage to not need conversion to floating point numbers.)