Your code will get accepted with slight modifications.
The main redundancy there is repeatedly checking certain n.
for example, the input set
will regenerate all the numbers from 0 to 300.
As such, you should pre-generate and check for primality all the numbers.
After which, just loop through and do some counting
thats how i did it anyway
My 2 cents worth