-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP33.java
38 lines (34 loc) · 992 Bytes
/
P33.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
package euler;
public class P33
{
public static void main(String[] args)
{
int totalTop=1, totalBottom=1;
for (int top=10; top<100; top++)
for (int bottom=top+1; bottom<100; bottom++) // cannot exceed 1.0
{
if (top%10==0 && bottom%10==0)
continue;
int gcd=Factors.gcd(top, bottom);
if (gcd!=1)
{
int t=top/gcd, b=bottom/gcd;
double divInitial=(double)top/(double)bottom;
if ( top%10==bottom/10)
{
int t1=(top/10), b1=bottom%10;
double divReduced=(double)t1/(double)b1;
if (divInitial==divReduced)
{
System.out.format("%d/%d=%f, with gcd=%d leading to %d/%d", top, bottom, divInitial, gcd, t, b);
System.out.format(" *** match ***%n");
totalTop *= t1;
totalBottom *= b1;
}
}
}
}
int totalGCD = Factors.gcd(totalTop, totalBottom);
System.out.format("All done, with product of the results = %d/%d%n", totalTop/totalGCD, totalBottom/totalGCD);
}
}