Thanks for letting us know which test, it allowed me to put in your code and test it.
I see your code actually works when put into the problem, although I found it a little confusing to work my brain through :). Problem is that it just can’t pass the last test of 10001 because it times out. So yes, definitely need to increase the efficiency.
One thing to note about testing to see if a number is a prime, you don’t need to check every number below the desired number to see if it divides. For instance, lets find out if 15 is prime.
We can start at 2 because every number is divisible by 1 (although you compensate for that by checking to verify if your counter is 2 ).
2 * nothing = 15
3 * 5 = 15
4 * nothing = 15
5 * 3 = 15
we could continue but there are no others.
If you notice, we did unnecessary work. We spend the time to check if 3 was divisible, but then we also checked 5… but based on previous test of 3, we already knew 5 divided. Can you figure it out from there?
If not: SPOILER ALERT:
Basically, when checking to see if a number is prime, you only need to check up to and including the square root of the number your searching because past its sqrt any number that divides with it would have already been checked by a number below the sqrt.
This doesn’t matter for a smaller number, but lets say for 100, instead of checking 99 numbers to see if any divide, we only really need to check up to 10 (the sqrt) because
2 * 50 = 100 ( basically meaning 100 % 2 = 0 )
4 * 25 = 100 ( basically meaning 100 % 4 = 0 )
5 * 20 = 100 ( basically meaning 100 % 5 = 0 )
10 * 10 = 100 ( basically meaning 100 % 10 = 0 )
20 * 5 = 100 ( basically meaning 100 % 20 = 0 )
25 * 4 = 100 ( basically meaning 100 % 25= 0 )
50 * 2 = 100 ( basically meaning 100 % 50 = 0 )
so anything past 10 was just repeating work. As you get into the thousands this saves TONS of time.
I rewrote your code with this in mind and it does pass… won’t spoil anything further by giving specifics 