-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEuler_69
More file actions
33 lines (31 loc) · 793 Bytes
/
Euler_69
File metadata and controls
33 lines (31 loc) · 793 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
public class prob_69 {
/**
* @param args
*/
public static void main(String[] args) {
double tMax = 0;
int ans = 0;
for (int i=2; i<1000000; i++){
if(i%2!=0 || i%3!=0 || i%5!=0 || i%7!=0 || i%11!=0 ) || i%13!=0 || i%17!=0)
continue; //optimization--answer also equal to the product of these primes
double tRat = 1;
int k = i;
//TOTIENT FUNCTION
for(int j=2; j<=k; j++){
if(k%j == 0){ //input is a factor of i
tRat *= (j/(double)(j-1)); //Euler's product formula
while(k % j == 0){ //reduce input by that factor
k /= j;
}
}
if(tRat > tMax){
tMax = tRat;
ans = i;
System.out.println("max rat " + tMax);
System.out.println("temp ans is: " + ans);
}
}
}
System.out.println("ans is "+ans);
}
}