-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem3.java
More file actions
49 lines (38 loc) · 722 Bytes
/
Copy pathproblem3.java
File metadata and controls
49 lines (38 loc) · 722 Bytes
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
46
47
48
49
public class problem3 {
/**
* Problem 3
* The prime factors of 13195 are 5, 7, 13 and 29.
* What is the largest prime factor of the number 600851475143 ?
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String no = "600851475143";
Long primeFactor = Long.decode(no);
long max = 0;
for(int i =1;i < 100000; i++){
if(prime(i) && primeFactor % i == 0)
{
if ( i > max){
max = i;
}
}
}
System.out.print(max);
}
public static boolean prime(int n){
if(n == 1){
return false;
}
if(n == 2){
return true;
}
else{
for(int i= 3;i<n;i++){
if ( n % i == 0){
return false;
}
}
}
return true;
}
}