欧拉工程第55题:Lychrel numbers
package projecteuler51to60; import java.math.BigInteger;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet; class level55{
void solve0(){
int Max=10000;
int count=0;
for(int i=0;i<Max;i++){
if(isLychrel(i))
count++;
}
System.out.println(count);
}
private boolean isLychrel(int n){
BigInteger temp = BigInteger.valueOf(n);
for(int i=0;i<49;i++){
BigInteger revtemp = new BigInteger(reverse(temp.toString()));
temp = temp.add(revtemp);
if(isPalindrome(temp.toString())){
return false;
} }
return true;
}
String reverse(String s) {
return new StringBuilder(s).reverse().toString();
}
public boolean isPalindrome(String s) {
return s.equals(reverse(s));
}
public boolean isPalindrome(int x) {
return isPalindrome(Integer.toString(x));
}
}
public class Problem55 { public static void main(String[] args){
long begin= System.currentTimeMillis();
new level55().solve0();
long end = System.currentTimeMillis();
long Time = end - begin;
System.out.println("Time:"+Time/1000+"s"+Time%1000+"ms");
} }
欧拉工程第55题:Lychrel numbers的更多相关文章
- 欧拉工程第69题:Totient maximum
题目链接 欧拉函数φ(n)(有时也叫做phi函数)可以用来计算小于n 的数字中与n互质的数字的个数. 当n小于1,000,000时候,n/φ(n)最大值时候的n. 欧拉函数维基百科链接 这里的是p是n ...
- 欧拉工程第70题:Totient permutation
题目链接 和上面几题差不多的 Euler's Totient function, φ(n) [sometimes called the phi function]:小于等于n的数并且和n是互质的数的个 ...
- 欧拉工程第61题:Cyclical figurate numbers
---恢复内容开始--- 题目链接 从三角数开始,循环到八角数,再到三角数,求这6个数的和 这个比较复杂,代码在网上找的 Java: package project61; import java.ut ...
- 欧拉工程第67题:Maximum path sum II
By starting at the top of the triangle below and moving to adjacent numbers on the row below, the ma ...
- 欧拉工程第66题:Diophantine equation
题目链接 脑补知识:佩尔方差 上面说的貌似很明白,最小的i,对应最小的解 然而我理解成,一个循环的解了,然后就是搞不对,后来,仔细看+手工推导发现了问题.i从0开始变量,知道第一个满足等式的解就是最小 ...
- 欧拉工程第65题:Convergents of e
题目链接 现在做这个题目真是千万只草泥马在心中路过 这个与上面一题差不多 这个题目是求e的第100个分数表达式中分子的各位数之和 What is most surprising is that the ...
- 欧拉工程第56题:Powerful digit sum
题目链接 Java程序 package projecteuler51to60; import java.math.BigInteger; import java.util.Iterator; im ...
- 欧拉工程第54题:Poker hands
package projecteuler51to60; import java.awt.peer.SystemTrayPeer; import java.io.BufferedReader; impo ...
- 欧拉工程第53题:Combinatoric selections
package projecteuler51to60; class p53{ void solve1(){ int count=0; int Max=1000000; int[][] table=ne ...
随机推荐
- MS Chart-按照数据库的最大最小时间设置X轴label.
核心代码: Chart1.ChartAreas[0].AxisX.Interval = (Front_Max - Front_Min).Days / 2; Chart1.ChartAreas[0].A ...
- 引用类型a=b
List<int> list = new List<int>(); list.Add(1); list.Add(2); list.Add(3); Cache["Key ...
- php捕获网络页面
<?php $url = 'http://jwzx.cqupt.edu.cn/pubYxKebiao.php?type=zy&yx=06'; $html = file_get_conte ...
- ASP.NET中Global.asax 文件是什么?
Global.asax 文件,有时候叫做 ASP.NET 应用程序文件,提供了一种在一个中心位置响应应用程序级或模块级事件的方法.你可以使用这个文件实现应用程序安全性以及其它一些任务.下面让我们详细看 ...
- vbs操作txt文本文件常用方法(函数)
创建文件 dim fso, f set fso = server.CreateObject("Scripting.FileSystemObject") set f = fso.Cr ...
- nodeJs爬虫获取数据
var http=require('http'); var cheerio=require('cheerio');//页面获取到的数据模块 var url='http://www.jcpeixun.c ...
- 任务:写一个tomcat自启动脚本
写一篇<gitlab无法启动了应该怎么办>
- MyEclipse构建WebService案例
Hi,大家好! 今天主要和大家分享,如何搭建一个Web服务,做Android开发,不可避免会涉及到客户端开发,我们怎么样来实现一个服务端,怎么样来实现一个客户端,并相互传递数据.就算调用别人的服务时, ...
- window8左下角窗口和右上角窗口失效解决方法
win8系统有时会出现任务栏和桌面点击没反应 小常识: “Windows徽标键” 这个键,左右各一个,称为“Windows徽标键”,键冒上的图案为Windows徽标,由此得名. [知识链接]位于计算机 ...
- SPOJ-SQRBR Square Brackets
原题传送:http://www.spoj.pl/problems/SQRBR 动态规划. 设f[i][j]表示前i个位置在合法情况下缺少j个右括号的方案数. 转移方程为: f[i][j] = f[i- ...