i am failing two test cases out of 9 in this ques. i could not find error in it
can you please help me out.
code-
import java.util.*;
public class Main{
public static void main(String[] args) throws Exception {
Scanner s = new Scanner(System.in);
int n =s.nextInt();
String str = s.next();
String ans = new String();
int count=0;
long i=0;
while(i < str.length()) {
long j=i+1;
while(j<= str.length()) {
ans = str.substring((int)i,(int)j);
long num = Long.parseLong(ans);
if(prime(num)) {
count++;
i=j;
}
j++;
}
i++;
}
System.out.println(count);
}
public static boolean prime(long num) {
if(num==0||num==1){
return false;}
for(int i=2;i*i<=num;i++){
if(num%i==0){
return false;
}
}
return true;
}
}