project euler-34
145是个奇怪的数字。由于1!+ 4! + 5! = 1 + 24 + 120 = 145。
请求出能表示成其每位数的阶乘的和的全部数的和。
请注意:由于1! = 1和2! = 2不是和,故它们并不包含在内。
---------------------------------------------------
原来0的阶乘是1。。。。我弱智了。。。
粗略的运算一下数据范围。发现不会超过1000W。
于是,暴力吧。
。
(事实上结果仅仅有两个数符合规律。
。。)
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<string.h>
#include<math.h>
using namespace std;
int fat[10];
void init()
{
fat[0]=1;
fat[1]=1;
for(int i=2;i<=9;i++)
{
fat[i]=fat[i-1]*i;
}
}
int cal(int x)
{
int ans=0;
while(x)
{
ans=ans+fat[x%10];
x=x/10;
}
return ans;
}
int main()
{
init();
int sum=0;
for(int i=10;i<=100000000;i++)
{
if(i==cal(i))
{
sum+=i;
}
}
cout<<sum<<endl;
return 0;
}
project euler-34的更多相关文章
- Project Euler 34 Digit factorials
题意:判断一个数 N 的各个位数阶乘之和是否为其本身,找出所有符合要求的数然后求和 思路:此题思路跟 30 题相同,找到枚举上界 10 ^ n <= 9! × n ,符合要求的 n < 6 ...
- Python练习题 039:Project Euler 011:网格中4个数字的最大乘积
本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...
- Python练习题 035:Project Euler 007:第10001个素数
本题来自 Project Euler 第7题:https://projecteuler.net/problem=7 # Project Euler: Problem 7: 10001st prime ...
- Python练习题 030:Project Euler 002:偶数斐波那契数之和
本题来自 Project Euler 第2题:https://projecteuler.net/problem=2 # Each new term in the Fibonacci sequence ...
- [project euler] program 4
上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...
- Python练习题 029:Project Euler 001:3和5的倍数
开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...
- Project Euler 9
题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...
- 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 ...
- project euler 169
project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...
- 【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 × ...
随机推荐
- rsync 和 inotify 结合
我们知道 rsync 可以实现推送和拉取,而 inotify-tools 借助内核的 inotify 机制实现了文件的 实时监控.因此,借助这个思路,我们可以通过使用 shell 脚本,调整 inot ...
- more - 在显示器上阅读文件的过滤器
总览 (SYNOPSIS) more [-dlfpcsu ] [-num ] [+/ pattern] [+ linenum] [file ... ] 描述 (DESCRIPTION) More 是 ...
- open, creat - 用来 打开和创建 一个 文件或设备
SYNOPSIS 总览 #includ e <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int o ...
- uniq 去除重复行
1.命令功能 uniq可以输出或忽略文件中的重复行,经常需要使用sort先对文件进行排序,然后使用uniq去重并计数. 2.语法格式 uniq option input uniq 选项 ...
- fork和vfork的区别
参见百度百科API说明: fork 头文件: #include<unistd.h> #include<sys/types.h> 函数原型: pid_t fork( void); ...
- Centos7 tomcat 启动权限
Cannot find bin/catalina.sh The file is absent or does not have execute permission This file is ne ...
- 一、ARM
1.1 ARM 分类 1.1.1 版本号分类 以前分类的是 ARM7,ARM9... ARM11,在 ARM11 之后,就是以 Cortex 系列分类了: Cortex-R:应用在实时系统上的系列 C ...
- [BZOJ1826] 缓存交换
问题描述 在计算机中,CPU只能和高速缓存Cache直接交换数据.当所需的内存单元不在Cache中时,则需要从主存里把数据调入Cache.此时,如果Cache容量已满,则必须先从中删除一个. 例如,当 ...
- 对Promise的研究2
3.Promise.prototype.then() Promise 实例具有then方法,也就是说,then方法是定义在原型对象Promise.prototype上的.它的作用是为 Promise ...
- OC 类的load方法
+(void)load 方法 不需要主动调用,类加载时会走这个方法