Solve SPOJ problem #2, PRIME1