懒得写高精度。直接用java模拟了一下好了
import java.math.BigInteger;
import java.util.*;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int ans = 0;
for(int i = 1; i < 10000; i++)
{
BigInteger x = BigInteger.valueOf(i);
int flag = 0;
for(int j = 0; j < 50; j++)
{
String str = x.toString();
String strReverse =new StringBuffer(str).reverse().toString();
BigInteger a = new BigInteger(str);
BigInteger b = new BigInteger(strReverse);
x = a.add(b);
String tmp = new StringBuffer(x.toString()).reverse().toString();
BigInteger y = new BigInteger(tmp);
if(x.equals(y))
{
flag = 1;
break;
}
}
if(flag == 0) ans++;
}
System.out.println(ans);
}
}