Prime visit program

import java.util.*;

public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
int arr[] = new int[1000005];
// System.out.print(arr[0]);
primeSieve(arr);
while (n-- > 0) {
int count = 0;
int a = cin.nextInt(), b = cin.nextInt();
for (int i = a; i <= b; i++) {
if (arr[i] == 1) {
count++;
}
}
System.out.println(count);
}
}
public static void primeSieve(int[] prime) {
for(int i=2;i<prime.length;i++)
prime[i] = 1;

for(int p = 2; p <prime.length; p++)
{
// If prime[p] is not changed, then it is a prime
if(prime[p] == 1)
{
// Update all multiples of p
for(int i = p; i < prime.length; i += p)
prime[i] = 0;
}
}
}
}
where i went wrong in the code i am stuck up and on comiling it is showing 0 as output on running

Hey @karthik1989photos
There are two changes in your code
First One is Size of array arr
Second one is inside primeSieve
correct Code :

sir can u plz explain the codeinside primeseive

@karthik1989photos
for (int p = 2; p < prime.length; p++) { //
// If prime[p] is a prime
if (prime[p] == 1) {
// Update all multiples of p
for (int i = 2; i*p < prime.length; i ++)
prime[i*p] = 0;
}

can u plz explain the whole code imnot getting it

@karthik1989photos
just tell me you know
sieve of eratosthenes concept

Create a int array “prime[0…n]” and initialize

// all entries it as 1. A value in prime[i] will

/ finally be 0 if i is Not a prime, else 1. `

boolean prime[] = new boolean [n+1`];

for(int i= 0 ;i<n;i++) `

prime[i] = 1 ;

for ( int p = 2 ; p*p <=n; p++)

{

// If prime[p] is 1 not changed, then it is a prime

if (prime[p] == 1 )

{

// Update all multiples of p

for ( int i = p* 2 ; i <= n; i += p)

prime[i] = false ;

}

}