Prime visits question doubt

I am not getting the given sample test case.
Here is the question https://hack.codingblocks.com/contests/c/916/63

@ranjanpanda
The problem says you to count the no of countries having integer with only two divisors. We know only prime numbers are the numbers having two divisors - 1 and the number itself.
You just have to count the no of primes in the given range (both the limits included)
Sample Input:
2
1 10
11 20
Sample Output:
4
4

Primes between 1-10 : 2,3,5,7
Primes between 11-20 : 11,13,17,19
Both testcases print 4

1 Like

Thank you. Great explanation Tarun sir.
Sir, but my code seems to be incorrect and I can’t find my mistake. Please help.
Here’s my code - https://ide.codingblocks.com/s/113684

@ranjanpanda
You have not marked integer 2 as prime. It is marked as 0 and hence counts as a non-prime number in your code.
Add this statement
p[2] = 1;

Also , to prevent the runtime error in your code , use long long int instead of int for loop variables i and j and the computations of square get large and the value of j is likely to overflow range of int. In such a case , it gets a -ve value and tries to access a -ve array location thus giving the error.
Use long long int for your loop variables and the problem should be solved.

1 Like

Never had anyone explaining my doubts so well. Thanks a lot sir. 5 stars.:star_struck:

@ranjanpanda
Thank you. Glad I could be of help.

1 Like