欧拉项目第四题 Largest palindrome product
2016-03-09 09:36
357 查看
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.
回文数 从左往右写 与 从右往左写是一样的,两个两位数的乘积是回文数的最大值是9009=91*99
求两个三位数乘机是回文数的最大值
其实就是求 10000-998001之间、可由两个三位数的乘机的最大回文数
我的想法是,列举回文数,一个个暴力破解
假设6位回文数是xyzzyx,x是1-9,y、z是0-9,5位的暂不考虑
906609=913*993
Find the largest palindrome made from the product of two 3-digit numbers.
回文数 从左往右写 与 从右往左写是一样的,两个两位数的乘积是回文数的最大值是9009=91*99
求两个三位数乘机是回文数的最大值
其实就是求 10000-998001之间、可由两个三位数的乘机的最大回文数
我的想法是,列举回文数,一个个暴力破解
假设6位回文数是xyzzyx,x是1-9,y、z是0-9,5位的暂不考虑
public static void main(String[] args) { for(int x = 9;x>=1;x--){ for(int y = 9;y>=0;y--){ for(int z = 9;z>=0;z--){ int hw = x * 100000 + y * 10000 + z* 1000 + z * 100 + y * 10 + x; if(check(hw)) { System.out.println(hw); System.exit(0); } } } } } public static Boolean check(int num){ for(int i=100;i<Math.sqrt(num);i++){ if(num%i==0 && num/i >= 100 && num/i <= 999) { System.out.println(num + "=" + i + "*" + num/i); return true; } } return false; }结果是
906609=913*993
相关文章推荐
- 学习进度条
- "WARNING: Increasing RAM size to 1GB" and "Cannot set up guest memory 'xxx.ram': Invalid argument".
- 堆排序算法
- Spring AOP: proxy-target-class 值的意思
- 抓取Android应用的log
- 民数记研读1——于宏洁
- lzg_ad:XPE常见问题FAQ
- 深入理解js闭包
- Gnuplot使用技巧:线和点的种类(Line and Point Types)
- 类的相关知识
- Mybatis关联查询(嵌套查询)
- 2016年3月9日Android实习日记
- 每天定时去女友空间留言工具(首选你要有个女友。!哈哈哈哈)
- 大端字节(big-endian)和小端字节(little-endian):到底哪些地方要注意字节顺序
- Windows平台分布式架构实践 - 负载均衡
- 在Windows中构建基于Docker的一致性开发环境
- ASP.NET 文件的下载
- 方法的调用
- Android上玩玩Hook?
- PHP字面量与标识符