Project Euler #123: Prime square remainders

  • + 0 comments

    I am trying this with C++. My approach is as follow: -> Find all prime below 3000 (Just random number for testing) -> Calculate reminder using formula as per problem description and store the same in vector. -> Loop through all test cases and use upper_bound on vector related to calculated reminder.

    I am not getting last two test cases correct. I am able to find issue but do not know what is the solution for the same.

    While calculating reminder, I have used data type as long double. For prime number pn = 1223 and n = 200, summation of nth power is going out of limit for double data type. Any idea how to solve this using CPP?