题意:判断一个数 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的更多相关文章

  1. 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 ...

  2. Project Euler 33 Digit cancelling fractions

    题意:49/98是一个有趣的分数,因为可能在化简时错误地认为,等式49/98 = 4/8之所以成立,是因为在分数线上下同时抹除了9的缘故.分子分母是两位数且分子小于分母的这种有趣的分数有4个,将这四个 ...

  3. Project Euler 30 Digit fifth powers

    题意:判断一个数 N 的每一位的5次方的和是否为其本身 ,求出所有满足条件的数的和 思路:首先设这个数 N 为 n 位,可以简单的判断一下这个问题的上界 10 ^ n <= 9 ^ 5 × n, ...

  4. (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 ...

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

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

  6. Python练习题 044:Project Euler 016:乘方结果各个数值之和

    本题来自 Project Euler 第16题:https://projecteuler.net/problem=16 ''' Project Euler 16: Power digit sum 2* ...

  7. Python练习题 039:Project Euler 011:网格中4个数字的最大乘积

    本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...

  8. Python练习题 035:Project Euler 007:第10001个素数

    本题来自 Project Euler 第7题:https://projecteuler.net/problem=7 # Project Euler: Problem 7: 10001st prime ...

  9. Python练习题 030:Project Euler 002:偶数斐波那契数之和

    本题来自 Project Euler 第2题:https://projecteuler.net/problem=2 # Each new term in the Fibonacci sequence ...

随机推荐

  1. Spring MVC-表单(Form)标签-文本框(Text Box)示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_textbox.htm 说明:示例基于Spring MVC 4.1.6. 以下示例 ...

  2. Java基础教程:tutorialspoint-spring mvc

    教程: 来自turorialspoint的Spring MVC 4.1.6教程(英文),官网:https://www.tutorialspoint.com/springmvc/index.htm 离线 ...

  3. 《coredump问题原理探究》Linux x86版7.7节 set对象

    看一下bits/stl_map和bits/stl_set能够看到map和set的定义例如以下: 84 template <typename _Key, typename _Tp, typenam ...

  4. MySQL改动rootpassword的多种方法

     方法1: 用SET PASSWORD命令 mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newp ...

  5. 【MongoDB】windows平台搭建Mongo数据库复制集(相似集群)(三)

    关于windows平台搭建Mongo数据库复制集这个话题,我已经在前面写了两篇博客 第一篇: 怎样在windows平台搭建Mongo数据库复制集 第二篇: 数据同步和故障自适应測试 在本篇里面,咱们重 ...

  6. 2016.04.22,英语,《Vocabulary Builder》Unit 17

    anim, comes from the Latin anima, meaning 'breath' or 'soul'. animism: ['ænɪmɪzəm] n. 泛灵论,精神存在论,神创宇宙 ...

  7. vim相关资料

    http://www.360doc.cn/article/15064667_402846667.html http://blog.jobbole.com/86809/ http://blog.csdn ...

  8. 函数和指针 C++

    一.用函数指针变量调用函数. 指针变量也可以指向一个函数,一个函数在编译时被分配给一个入口地址.这个函数入口地址就称为函数的指针.可以用一个指针变量指向函数,然后通过该指针变量调用此函数. 定义指向函 ...

  9. Jquery 重置表单

    1.重置表单回初始状态 $('#fromid')[0].reset(); 此方法一步到位,不需要一个个的去赋值为空

  10. lua队列实现

    Queue = {} function Queue.newquene() } end function Queue.push(queue, value) queue.count = queue.cou ...