I was finding out highest prime factor which divides num, as shown in program, there\'s a issue with array and
arr[j] = i;
j++;
Excepti
This line
int arr[] = {j};
Creates an array that only contains the value of j
when it is executed. You probably want
int arr[] = new int[j];
UPDATE: Based on the answer you left below, trial division is taking too long. The Sieve of Eratosthenes is a classic algorithm that is pretty efficient, but the Sieve of Atkin is one of the most advanced algorithms for finding primes.