Prime Factor Problem Time Limit
Input: The only integer (N<=10^9): 999999937 Output: Each line contains its respective prime and exponent divisors. The prime factors areexported in ascending order: 999999937 1 When I try this test case, it takes some times to run and display output (on some compilers, it shows time limit or time out). How to fix that? import java.util.Scanner; public class Factor { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int n, count, m = 0; System.out.print("Enter number: "); n = keyboard.nextInt(); n = Math.abs(n); count = 0; for (int i = 2; i <= n; i++) { while (n % i == 0) { if (n % i == 0) { count++; m = i; } n = n / i; } if (m != 0 && count != 0) { if (n % i != 0) { System.out.printf("%d %d\n", m, count); count = 0; m = 0; } } } } }