-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp055.java
More file actions
33 lines (26 loc) · 702 Bytes
/
p055.java
File metadata and controls
33 lines (26 loc) · 702 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 level03;
import org.junit.Test;
import lib.EulerTest;
public class p055 extends EulerTest {
final int N = 10000;
final int K = 50;
/**
* Find the number of Lychrel numbers below N, defined as a number that does not form a
* palindrome after adding tself to its reverse K times.
*/
@Test
public void test() {
for (int i : range(N))
if (isLychrel(i + ""))
ans++;
check(249);
}
boolean isLychrel(String s) {
for (int i = 0; i < K; i++) {
s = big(s).add(big(sb(s).reverse())) + "";
if (isPalindrome(s))
return false;
}
return true;
}
}