-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path#3_largest_prime_factor.java
More file actions
45 lines (34 loc) · 1.06 KB
/
#3_largest_prime_factor.java
File metadata and controls
45 lines (34 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static long getFactor (long a){
long max = (long)Math.sqrt(a);
for(long i = 2; i <= max; i++){
if(a%i==0){
return i;
}//end if
}//end for
return -1;
}//end isPrime
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner in = new Scanner(System.in);
int tests = in.nextInt();
for(int test = 1; test<=tests; test++){
long n = in.nextLong();
long temp = n;
for(long i = 0; i < n; i++ ){
long factor = getFactor(temp);
if(factor!=-1){
temp/=factor;
}else{
break;
}
}
System.out.println(temp);
}//end for
}
}