You are viewing a single comment's thread. Return to all comments →
Java: I dont know how to make it faster...
public class Solution { private static Map<Long,Boolean> primeMap = new HashMap<>(); public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int a0 = 0; a0 < t; a0++){ long n = in.nextLong(); for(long i=n;i>2;i--){ if(n%i!=0) continue; boolean iIsPrime = true; if(!primeMap.containsKey(i)){ for(int j=2;j<=Math.sqrt(i);j++){ if(i%j==0&&j!=i){ iIsPrime=false; break; } } primeMap.put(i, iIsPrime); } else { iIsPrime = primeMap.get(i); } if(iIsPrime){ System.out.println(i); break; } } } } }
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 →
Java: I dont know how to make it faster...