求最大的回文数,同时回文数是2个三位数的乘积

/**
* 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.
*/

代码:

private static int largePalin(int n) {
if (n < 1)
return 0;
int max = (int) Math.pow(10, n) - 1;
int min = (int) Math.pow(10, n - 1);
int palin = 0;
for (int i = max; i >= min; i--) {
palin = generatePalin(i);
for (int j = (int) Math.sqrt(palin); j >= min; j--) {
if (palin % j == 0 && palin / j >= min && palin / j <= max) {
return palin;
}
}
}
return palin;
}

private static int generatePalin(int n) {
int sum = 0;
for (sum = n; n > 0; n = n / 10) {
sum = sum * 10 + n % 10;
}
return sum;
}

public static void main(String[] args) {
System.out.println(largePalin(3));
}

思想:

1、2个3位数乘积必然是一个6位数,那么就可以由最大的3位数开始构造最大6位数的乘积

2、得到这个回文数判断他是否是2个3位数的成绩,因为这个回文数很大,可以考虑从这个回文数的平方判断是否存在2个3位数的因子

转载于:https://www.cnblogs.com/lake19901126/archive/2013/04/27/3047237.html

ProjectEuler 4相关推荐

  1. 51Nod-2173 ProjectEuler 71

    2173 ProjectEuler 71 1.0 秒 131,072.0 KB 20 分 初学者3级题 考虑分数a / b,其中a和b是正整数,如果a < b且a和b的最大公约数是1,我们说他是 ...

  2. 有关projecteuler题库621题的lisp解答,萌新求围观。

    projecteuler题库 https://projecteuler.net/problem=621 https://pastebin.ubuntu.com/p/w2G5bwbJMR/ 设T(n)是 ...

  3. [projecteuler]Counting Sundays

    题目:  http://projecteuler.net/problem=19 思路: 求每年的每个月的1号距离1990,1,1的天数 代码: #include <iostream>usi ...

  4. ProjectEuler 005题

    题目: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any ...

  5. [projectEuler.net]12

    求一个数的因子的数量. X=a^n*b^m*c^p will have (n + 1)(m + 1)(p + 1) factors.//abc都是质因子28=2^2*7 will have 3*2 = ...

  6. ProjectEuler 2

    Fibonacci数列的每一项是之前两项的和. Fibonacci数列以1和2开始,前10项是 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, - 输入一个n,求所有小于等于n, ...

  7. ProjectEuler 5

    6是最小的,1到3所有数的倍数.(6 = 1 * 6 = 2 * 3 = 3 * 2) 2520是最小的,1到10的所有数字的倍数. 输入n,输出最小的正整数,他是1到n所有数的倍数 Input 输入 ...

  8. 51Nod 2188 ProjectEuler 24

    考虑0, 1, 2,共3个数字的所有排列,按字典序排列为 012 021 102 120 201 210 输入n,考虑0, 1, 2, 3, 4, 5, 6, 7, 8 和 9 共10个数字的所有排列 ...

  9. ProjectEuler Problem1.Multiples of 3 and 5

    题目链接:1.Multiples of 3 and 5 题意:   求小于1000的3和5的倍数的和 解题   可以使用循环,也可以直接分析,等差数列求和(注意,3和5的公倍数只需计算一次,多计算的减 ...

最新文章

  1. jetty java 实例_Maven+Jetty+Servlet 简单示例
  2. Netty事件传播机制
  3. MySQL高级 - 锁 - InnoDB行锁 - 行锁升级为表锁
  4. HLS_error implicit instantiation of undefined template ‘ssdm_int
  5. Error-Project facet Java version 1.8 is not supported
  6. centos7 安装Golang环境
  7. day-01(html)
  8. js简单判断身份证合法性以及身份证生日合法性
  9. OSTimeGet()--获取当前时间
  10. 基于JAVA+SpringMVC+MYSQL的苗木销售系统
  11. 常用自动化测试工具介绍(支持B/S、C/S)
  12. Microsoft Office Visio 2007和Microsoft Office Project 2007下载
  13. ug80浩强工具_ug浩强工具-ug浩强工具下载 2.59 免费版 - 河东下载站
  14. 西南科技大学OJ题 舞伴问题1027
  15. (1.5万字图文)解读华为集成产品开发IPD之市场管理流程(MM流程)
  16. 一位基金经理13年的期货感悟
  17. Laravel Eloquent If Record Exists
  18. 鸿蒙系统盲测,小米5S重磅领衔:一图看懂小米2016秋季新品发布会!
  19. 【数据库修复】Mallox勒索病毒家族的数据库文件可100%修复
  20. android自动生成dimens适配文件

热门文章

  1. 【深度学习】keras框架使用预训练模型进行Finetune的应用
  2. python【蓝桥杯vip练习题库】ALGO-66字符串编辑
  3. 频域采样与恢复matlab实验,连续信号的采样与重构实验报告
  4. 图示评审技术_编制清单报价最需要施工技术课程中的哪些知识?
  5. h5 iframe显示不全_H5 唤醒APP小记
  6. linux 版本 arch,Arch Linux是什么
  7. 百度网络推广介绍网站在更换老域名时都需注意哪些?
  8. seo优化无法避免却又无可奈何的问题
  9. 浅析那些你不知道的提升企业网站转化率的SEO优化技巧 !
  10. 挂代理无法访问网页了怎么办_搜索引擎蜘蛛不能爬取网页的原因有哪些