-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp033.java
More file actions
32 lines (26 loc) · 929 Bytes
/
p033.java
File metadata and controls
32 lines (26 loc) · 929 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
package level02;
import org.junit.Test;
import data.LFraction;
import lib.EulerTest;
public class p033 extends EulerTest {
final int B = 10;
/**
* Find the product of all ratios of 2-digit numbers [AB]/[CD] such that erroneously canceling
* [AB]/[CD] = A/D (if B=C) or [AB]/[CD] = B/C (if A=D) is still correct. Return the denominator
* of this product.
*/
@Test
public void test() {
LFraction product = LFraction.integer(1);
for (int a = B; a < sq(B); a++)
for (int b = a + 1; b < sq(B); b++) {
LFraction f = LFraction.reduced(a, b);
if (a % B == b / B && LFraction.reduced(a / B, b % B).equals(f)
|| a / B == b % B && LFraction.reduced(a % B, b / B).equals(f)) {
product = product.multiply(f);
}
}
ans = product.den;
check(100);
}
}