Project Euler 34 Digit factorials
题意:判断一个数 N 的各个位数阶乘之和是否为其本身,找出所有符合要求的数然后求和
思路:此题思路跟 30 题相同,找到枚举上界 10 ^ n <= 9! × n ,符合要求的 n < 6 ,因此选择 9! × 6 作为上界
/*************************************************************************
> File Name: euler034.c
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年06月23日 星期五 13时52分58秒
************************************************************************/
#include <stdio.h>
#include <inttypes.h>
#define MAX_N 2177280
int32_t fac[10];
void init_fac(){
fac[0] = 1;
for(int32_t i = 1 ; i < 10 ; i++) fac[i] = fac[i-1] * i;
}
bool isNumber(int32_t n){
int32_t sum = 0 , x = n;
while(x){
sum += fac[ x % 10 ];
x /= 10;
}
return sum == n;
}
int32_t main(){
int32_t sum = 0;
init_fac();
for(int32_t i = 3 ; i <= MAX_N ; i++){
if( isNumber(i) ) sum += i;
}
printf("%d\n",sum);
return 0;
}
Project Euler 34 Digit factorials的更多相关文章
- Project Euler:Problem 34 Digit factorials
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. Find the sum of all numbers which are ...
- Project Euler 33 Digit cancelling fractions
题意:49/98是一个有趣的分数,因为可能在化简时错误地认为,等式49/98 = 4/8之所以成立,是因为在分数线上下同时抹除了9的缘故.分子分母是两位数且分子小于分母的这种有趣的分数有4个,将这四个 ...
- Project Euler 30 Digit fifth powers
题意:判断一个数 N 的每一位的5次方的和是否为其本身 ,求出所有满足条件的数的和 思路:首先设这个数 N 为 n 位,可以简单的判断一下这个问题的上界 10 ^ n <= 9 ^ 5 × n, ...
- (Problem 34)Digit factorials
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. Find the sum of all numbers which are ...
- Python练习题 047:Project Euler 020:阶乘结果各数字之和
本题来自 Project Euler 第20题:https://projecteuler.net/problem=20 ''' Project Euler: Problem 20: Factorial ...
- Python练习题 044:Project Euler 016:乘方结果各个数值之和
本题来自 Project Euler 第16题:https://projecteuler.net/problem=16 ''' Project Euler 16: Power digit sum 2* ...
- 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 ...
随机推荐
- 【ACM】hdu_1042_N!_201308071639
N!Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- Internal Temporary Tables
8.4.4 How MySQL Uses Internal Temporary Tables 这是MySQL手册中的一节,尝试补充了一些解释.用的版本是MySQL5.6.15社区版 In some c ...
- POJ 1679
求一次最小成树,求一次小生成树,若相等,则不唯一.否则,唯一. #include <iostream> #include <cstdio> #include <cstri ...
- python3字符编码错误
在3.x 这里返回的是bytes-like类型, 所以这里不需要释放编码 ,释放也没有意义, 而是应该encode 转换成我们需要的编码, 之所会造成类型错误,原因是就在这里. 他们返回的类型不一样, ...
- 生产上数据库大量的latch free 导致的CPU资源耗尽的问题的解决
中午的时候,我们生产上的某个数据库,cpu一直居高不下 通过例如以下的sql语句,我们查看当时数据库的等待,争用的情况: select s.SID, s.SERIAL#, 'kill -9 ' || ...
- HDOJ 5421 Victor and String 回文串自己主动机
假设没有操作1,就是裸的回文串自己主动机...... 能够从头部插入字符的回文串自己主动机,维护两个last点就好了..... 当整个串都是回文串的时候把两个last统一一下 Victor and S ...
- arm32位固定指令中怎么容纳32位变量
在ARM指令集汇编码中.32位有效马上数是通过______偶数位而间接得到的 A.循环左移 B.循环右移. C.逻辑左移. D.逻辑右移 答案为循环左移.为什么?还有最好解释一下逻辑移动和循环移动的概 ...
- HDU 1788 Chinese remainder theorem again 中国剩余定理
题意: 给定n,AA 以下n个数m1,m2···mn 则有n条方程 res % m1 = m1-AA res % m2 = m2-AA 问res的最小值 直接上剩余定理,嘿嘿 #include< ...
- 文件I/O操作——File类
在java.io包之中,File类是唯一一个与文件本身有关的操作类.它定义了一些与平台无关的方法来操作文件,通过调用File类提供的各种方法,能够完成创建.删除文件,重命名文件,判断文件的读写权限及文 ...
- 使用新的CSS类型对象模型
el.attributeStyleMap.set('padding', CSS.px(42)); const padding = el.attributeStyleMap.get('padding') ...