We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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?
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #123: Prime square remainders
You are viewing a single comment's thread. Return to all 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?