Kindly tell me why the program below stalls for a 12-digit number
import java.io.*;
import java.util.Scanner;
class primefactor
{
public static void main(String args[])
{
long num,i,j,count=0L,rem;
long ans;
System.out.println("Enter the number whose greatest prime factor is required:");
Scanner sc=new Scanner(System.in);
num=sc.nextLong();
for(i=1;i<=num;i++)
{
for(j=1;j<=i;j++)
{
if(i%j==0)
count=count+1;
}
if(count==2)
{
rem=num%i;
if(rem==0)
ans=i;
}
count=0;
}
System.out.println("The answer is "+ ans);
}
}
Thank You