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 ...
随机推荐
- eclipse jvm调优
1.初始参数 -Xms256m-Xmx1024m 2.在eclipse.ini中加入,注意一点的是D:/soft/eclipse-jee,这个目录必须存在,启动时并不会自动目录 -verbose:gc ...
- 0120Keeplived实现自动切换Mysql服务
转自http://biancheng.dnbcw.info/mysql/381020.html Keepalived+mysql 自动切换网络结构:VIP 192.168.88.200mysq11 1 ...
- Redis参数
phpredis是php的一个扩展,效率是相当高有链表排序功能,对创建内存级的模块业务关系 很有用;以下是redis官方提供的命令使用技巧: Redis::__construct构造函数$redis ...
- HDU 1912
坑,直接把公路看成X轴来做,然后,排序扫描一下,你懂的. #include <iostream> #include <algorithm> #include <cstdi ...
- 从编程的角度理解gradle脚本﹘﹘Android Studio脚本构建和编程[魅族Degao]
本篇文章由嵌入式企鹅圈原创团队.魅族资深project师degao撰写. 随着Android 开发环境从Eclipse转向Android Studio,我们每一个人都開始或多或少要接触gradle脚本 ...
- 一见钟情Sublime
打开 preferences -> Setting-User,加入下面代码 { "font_size": 14, "ignored_packages": ...
- Linux GDB程序调试工具使用简单介绍
GDB概述 GDB是GNU开源组织公布的一个强大的UNIX下的程序调试工具.也许,各位比較喜欢那种图形界面方式的,像VC.BCB等IDE的调试,但假设你是在UNIX平台下做软件,你会发现GDB这个调试 ...
- android小技巧:在activity中实现与绑定的fragment的回调
看到标题你可能会想是一个多么高大上的技巧呢?事实上非常一般就是自己定义回调函数. 首先我们知道activity之间的数据传递有几种方式: 一是startActivityForResut()启动一个ac ...
- oc5--方法
// main.m // 第一个OC类-方法2 #import <Foundation/Foundation.h> // 1.编写类的声明 @interface Iphone : NSOb ...
- python求两个列表的并集.交集.差集
求两个列表的差集 >>> a = [1,2,3] >>> b=[1,2] >>> ################################ ...