-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem055.java
More file actions
35 lines (35 loc) · 989 Bytes
/
Problem055.java
File metadata and controls
35 lines (35 loc) · 989 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
34
35
import java.math.BigInteger;
public class Problem055 {
public static boolean isPalindrome(BigInteger bg) {
if (bg.equals(reverse(bg))) {
return true;
}
return false;
}
public static BigInteger reverse(BigInteger bg) {
char[] c = String.valueOf(bg).toCharArray();
String s = "";
for (int i = c.length - 1; i >= 0; i--) {
s += c[i];
}
return new BigInteger(s);
}
public static boolean isLychrel(BigInteger num) {
for (int i = 0; i < 50; i++) {
if (isPalindrome(num.add(reverse(num)))) {
return false;
}
num = num.add(reverse(num));
}
return true;
}
public static void main(String[] args) {
int total = 0;
for (int i = 0; i < 10000; i++) {
if (isLychrel(BigInteger.valueOf(i))) {
total++;
}
}
System.out.println(total);
}
}