-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp045.java
More file actions
33 lines (26 loc) · 753 Bytes
/
p045.java
File metadata and controls
33 lines (26 loc) · 753 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 org.junit.Test;
import lib.EulerTest;
public class p045 extends EulerTest {
final long N = 40755;
/**
* Find the smallest triangular number>N that is also pentagonal and hexagonal.
* <p>
* Since every hexagonal number is triangular, find the smallest hexagonal number that is
* pentagonal.
*/
@Test
public void test() {
for (int i = 1; true; i++) {
long hexagonal = figurate(i, 6);
if (hexagonal > N && isPentagonal(hexagonal)) {
ans = hexagonal;
break;
}
}
check(1533776805);
}
boolean isPentagonal(long n) {
return isSq(1 + 24 * n) && isqrt(1 + 24 * n) % 6 == 5;
}
}