You are viewing a single comment's thread. Return to all comments →
Below is my code but one hidden test case is still failing, can someone help here?
import java.util.*;
public class Solution {
public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int a = 0; a < t; a++){ long n = sc.nextLong(); boolean isPrime=checkPrime(n); if(!isPrime){ HighestPrimeFactors(n);} else {System.out.println(n);} } sc.close(); } public static boolean checkPrime(long num){ int count=0; for(long i=1;i<=num;i++){ if(num%i==0){ count++; } } if(count==2) return true; else return false; } public static void HighestPrimeFactors(long n){ long max=0; for(long i=1;i<n;i++){ if(n%i==0){ if(checkPrime(i)==true && max<i){ max=i; } } } System.out.println(max); }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #3: Largest prime factor
You are viewing a single comment's thread. Return to all comments →
Below is my code but one hidden test case is still failing, can someone help here?
import java.util.*;
public class Solution {
}