Project Euler #123: Prime square remainders

  • + 0 comments

    This problem is pretty straightforward with the observations from Problem 120. Unless the input is , we could ignore even number (where the mod is always ).

    First begin with prime sieve which is large enough (half a million is more than enough) to satisfy the upper bound. As the odd mods are in increasing order, we could obtain a list of them in sorted order, then use binary search for each test case to find the answer in (I used bisect_right).

    And, don't forget that is , as there is no .