Largest palindrome product

 

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.

寻找能够分解为两个三位数乘积的回文数:

先分析,回文数范围在:100^2=10000到999^2=998001之间,暴力也可行……但适当剪枝会快一些

考虑100000及以上时,回文数能被11整除,在循环中就可以抛去其它部分数,解答会快一些。

还想用用时间换空间可以先打个质数表……之类的

 #include"stdio.h"
#include"stdlib.h"
#include"string.h" int palindrome(int a,int b) /*palindrome function:to test if a product is palindrome*/
{
int sum,i,j;
char num[];
sum=a*b;
itoa(sum,num,);
for(i=,j=strlen(num)-;i<j;i++,j--)
if(num[i]!=num[j])
return();
return();
} int main() /*problem4-Largest palindrome product*/
{
int i,j,max=,m1=,m2=;
for(i=;i>=;i--)
for(j=i;j>=;j--)
{
if(i%!=&&j%!=) //剪枝,i,j之中必有一个为11倍数
continue;
if(palindrome(i,j)==&&i*j>max)
{
max=i*j;
m1=i;
m2=j;
}
}
printf("max palindrome is %d=%d*%d\n",max,m1,m2);
return();
}

Problem4-Project Euler的更多相关文章

  1. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  2. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  3. Project Euler 9

    题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...

  4. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

  5. project euler 169

    project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...

  6. 【Project Euler 8】Largest product in a series

    题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...

  7. Project Euler 第一题效率分析

    Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...

  8. Python练习题 049:Project Euler 022:姓名分值

    本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...

  9. Python练习题 048:Project Euler 021:10000以内所有亲和数之和

    本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...

  10. Python练习题 047:Project Euler 020:阶乘结果各数字之和

    本题来自 Project Euler 第20题:https://projecteuler.net/problem=20 ''' Project Euler: Problem 20: Factorial ...

随机推荐

  1. wangEditor使用简记

    页面 <!--用父容器来控制宽度--> <div style="width:800px"> <!--用当前元素来控制高度--> <text ...

  2. Nginx限制访问次数和并发数

    Nginx限制访问速率和最大并发连接数模块--limit (防止DDOS攻击) http: ##zone=one或allips 表示设置名为"one"或"allips&q ...

  3. mysql关于timestamp字段相关内容

    发现5.6和5.7版本的创建表不一致,从5.6导出数据表创建sql文件,然后导入到5.7表会报错,timestamp不能为空 查看的sql_mode mysql5.0以上支持的三种模式 1. ANSI ...

  4. postgresql主从配置

    master:10.0.1.114 slaver:10.0.1.116 一.yum安装https://blog.csdn.net/weixin_41048363/article/details/803 ...

  5. Python多版本管理器-pyenv 介绍及部署记录

    一. pyenv简单介绍 在日常运维中, 经常遇到这样的情况: 系统自带的Python是2.x,而业务部署需要Python 3.x 环境, 此时需要在系统中安装多个Python版本,但又不能影响系统自 ...

  6. git第五节--git branch--分支管理

    @git branch :查看当前仓库所有分支,及当前所处的分支 @git branch XXX:创建分支XXX @git checkout XXX:切换到分支XXX下 @git checkout - ...

  7. 百度前端技术学院task34源码——会指令的小块2

    任务描述 增加新的指令如下: TRA LEF:向屏幕的左侧移动一格,方向不变 TRA TOP:向屏幕的上面移动一格,方向不变 TRA RIG:向屏幕的右侧移动一格,方向不变 TRA BOT:向屏幕的下 ...

  8. [游记] HEOI2018酱油记

    Day -1 在机房颓颓颓颓颓,晚上得知这次考试题本来是要给 ZJOI2018 用的,结果没用上..可想而知考试的难度.. 但愿不爆零 Day 0 坐了一上午火车,顺便找茁神犇拷了个 COD,然后接着 ...

  9. ASP.NET MVC实现剪切图片

    开发需要,我们需要对某一张图片进行剪切.就是说,获取图片某一区域.下面Insus.NET教大家轻便容易实现它. 首先写好一个处理函数,它建在MVC应用程序结构Utilities目录下: 准备好一张图片 ...

  10. 基于asp.net mvc的近乎产品开发培训课程(第四讲)

    演示产品源码下载地址:http://www.jinhusns.com/Products/Download  演示产品源码下载地址:http://www.jinhusns.com/Products/Do ...