I am trying to find the solution through Sieve but only one case is passing. I am precomputing all primes till 1000000 in an array and the doing the prefix sum. Then for each query ans = array[b] - array[a-1].
Prime Visits using precomputation and Sieve
Please save your code in coding blocks ide and share its link.