import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class Prime{
public boolean isPrime(long num){
for(long k=3;k<=num/2;k = k+2){
if(num%k == 0){ return false;}
}
return true;
}
}
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Prime p = new Prime();
Scanner st = new Scanner(System.in);
int t = st.nextInt();
if(t<1 || t > 10) { System.exit(0);}
for (int j = 0;j<t;j++){
long n = st.nextLong();
if(n<10 || n > Math.pow(10,12)) { System.exit(0);}
// System.out.println("new");
long max = 0;
if (n%2 == 0) { max = 2; }
for(long i=3;i<=n;i=i+2){
if(p.isPrime(i)){
// System.out.println("num:"+i);
if(n%i == 0) { max = i;}
}
}
System.out.println( max);
}
}
}
No comments:
Post a Comment