1 / 8
Jun 2022

Hi,
I was trying to solve the VECTAR8 - Primal Fear problem. It seemed pretty easy, I precalculated all prime numbers that satisfy the conditions of the problem from 1 to 1000000 and put them into a vector, so I only have to count the numbers not greater than given N. I don’ think I missed any “scary primes”, so I have no idea why I’m getting WAs.
Here’s the code with numbers precalculated:

Code was here

I have no idea what’s wrong. Did I miss a number?

  • created

    Jun '22
  • last reply

    Jul '22
  • 7

    replies

  • 649

    views

  • 3

    users

  • 1

    link

When I generate the list of scary primes, it doesn’t contain 2, 3, 5 or 7.

Did it accept your answer without counting these four numbers? That would be strange. They are all prime, have no zeroes in them and no matter how many leading numbers you omit they are still prime, because there is nothing to omit.
Especially since it counts it in the example under the problem:

Example

Input:
3
2
3
4

Output:
1
2
2

Sorry, you’re right. I misread my own code.

Try this test case:

1
998929

My answer is 671, yours is 676.

VECTAR87

Oh… When I say your reply I thought I’ll have to go through every number once again and look for these 5 false positives. But no, I just forgot to check one extreme case, namely N>=998443. Because of that that for loop never stopped when N >= 998443 and the program tried to access vector at indexes out of its range. My bad, should’ve seen that could become a problem.
Anyway, a single if statement was enough to get AC.
Thank you

Yep, well spotted.

Please could you remove your code above? Let’s try to minimise the copy’n’pastes.