-
Notifications
You must be signed in to change notification settings - Fork 0
/
E3.java
39 lines (37 loc) · 786 Bytes
/
E3.java
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
//What is the largest prime factor of a given number ?
import java.util.Scanner;
class E3
{
static long find( long n)
{
long maxPrime = -1;
while (n % 2 == 0)
{
maxPrime = 2;
n/=2;
}
for (int i = 3; i <= Math.sqrt(n); i += 2)
{
while (n % i == 0)
{
maxPrime = i;
n = n / i;
}
}
if (n > 2)
{
maxPrime = n;
}
return maxPrime;
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int x=0;x<t;x++)
{
long n=sc.nextLong();
System.out.println(find(n));
}
}
}