At first I tried to make a very efficient algorithm, but it gave wrong answer. So I made a brute force algorithm to generate answer for small values of n and then use them to cross check my efficient algorithm and find bugs. I was pretty sure my brute force algorithm would work for all n, but sadly it didn't.

This sadly revealed the answer, but I used the values to cross check my brute force approach. It works for n = 10, 100, 1000, 10^4, 10^5, 10^6, 10^7, but not for 10^8. The answer my program displays is one more than the correct answer. I have no idea why this is happening.

The file <eku\math\sqrt_uint.h> is my own and contains a function to calculate square root of an integer. The answer is rounded down if the parameter is not a perfect square.

The file containing the list of primes has never betrayed me in any Project Euler problem before, so there is very little chance that the file is wrong.

This might be a brute-force approach, but I don`t see any other efficient method of doing this except using hashmaps:

All you need to solve this is all the prime numbers below 10,000 (9973 and below). Store all the values 4-10^8 in a bool array and mark each one as true.

Now using 2 for-loops, go through all the primes you have and as you mark the product of the 2 for-loops as false, keep counting. When your for-loop is done, you have your answer if you print your counter variable.

E: The double for-loops should not scare you as there are only 1229 primes below 10000 so this code should run quite faster than O(1229^2)

EDIT: Note: The logic is unchanged from the code in the original post; but generates the prime numbers instead of reading them from a file. (And deduces an appropriate unsigned integral type capable of holding numbers up to 10^8).