-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp044.java
More file actions
33 lines (25 loc) · 777 Bytes
/
p044.java
File metadata and controls
33 lines (25 loc) · 777 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
package level02;
import java.util.Set;
import org.junit.Test;
import lib.EulerTest;
public class p044 extends EulerTest {
final int L = 3000;
/**
* Find the minimal difference between two pentagonal numbers A and B such that both A+B and A-B
* are also pentagonal.
*/
@Test
public void test() {
Set<Long> pentagonals = set();
for (int i : range(1, L))
pentagonals.add(figurate(i, 5));
ans = Long.MAX_VALUE;
for (long a : pentagonals)
for (long b : pentagonals) {
long d = Math.abs(a - b);
if (Math.abs(d) < ans && pentagonals.contains(a + b) && pentagonals.contains(d))
ans = d;
}
check(ans, 5482660);
}
}