(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 equal to the sum of the factorial of their digits.
Note: as 1! = 1 and 2! = 2 are not sums they are not included.
题目大意:
145 是一个奇怪的数字, 因为 1! + 4! + 5! = 1 + 24 + 120 = 145.
找出所有等于各位数字阶乘之和的数字之和。
注意: 因为 1! = 1 和 2! = 2 不是和的形式,所以它们不算在内。
//(Problem 34)Digit factorials
// Completed on Thu, 25 Jul 2013, 16:11
// Language: C
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/#include<stdio.h>
#include<math.h>
#include<stdbool.h> int factorial(int n) //阶乘函数
{
if(n== || n==) return ;
else return n*factorial(n-);
} bool judge(int n) //判断一个整数是否符合题意的函数
{
char s[];
sprintf(s,"%d",n);
int len=strlen(s);
int sum=;
for(int i=; i<len; i++)
{
sum+=factorial(s[i]-'');
}
if(n==sum) return true;
else return false;
} int main()
{
int sum=;
for(int i=; i<; i++)
{
if(judge(i))
sum+=i;
}
printf("%d\n",sum);
return ;
}
Answer:
|
40730 |
(Problem 34)Digit factorials的更多相关文章
- (Problem 74)Digit factorial chains
The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...
- (Problem 33)Digit canceling fractions
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...
- (Problem 16)Power digit sum
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of th ...
- (Problem 73)Counting fractions in a range
Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...
- (Problem 42)Coded triangle numbers
The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...
- (Problem 29)Distinct powers
Consider all integer combinations ofabfor 2a5 and 2b5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, ...
- (Problem 41)Pandigital prime
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...
- (Problem 70)Totient permutation
Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...
- (Problem 46)Goldbach's other conjecture
It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...
随机推荐
- cocos2d-x游戏开发(十六)帧动画
欢迎转载:http://blog.csdn.net/dawn_moon/article/details/11775745 本来想写一下帧动画的,搜了一下网上好像有一大把,就懒得写了,直接贴代码. // ...
- (Android) Chinese Character
Convert Chinese strings to English strings Apply pinyin4j.jar public static class ConvertChineseToPi ...
- 【JS控制图片显示的大小(图片等比例缩放)】
效果: 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...
- 获取当前WEB应用全路径
<%String path = request.getContextPath();String basePath =request.getScheme()+"://"+req ...
- 如果DataGrid的checkbox出现点一个另外自动点另一个现象
如果DataGrid的checkbox出现点一个另外自动点另一个现象: 取消(EnableRowVirtualization)这个选项就可以正常了(关闭虚拟UI):
- C++如何将一个整数输出为小数
double a=3; //一定是double不能是int cout.setf(ios::fixed); cout.precision(2); cout< ...
- BZOJ 1097: [POI2007]旅游景点atr( 最短路 + 状压dp )
先最短路预处理, 然后状压就行了 -------------------------------------------------------------------------- #include ...
- [NOIP2013提高组] CODEVS 3287 火车运输(MST+LCA)
一开始觉得是网络流..仔细一看应该是最短路,再看数据范围..呵呵不会写...这道题是最大生成树+最近公共祖先.第一次写..表示各种乱.. 因为要求运输货物质量最大,所以路径一定是在最大生成树上的.然后 ...
- C++重载赋值运算符
这是一道C++的面试题,下面在这篇博客中分析一下这个问题.先上题目: //题目:如下为类型CMyString的声明,请为该类型添加赋值运算符函数. class CMyString { public: ...
- mysql查询数据库中包含某字段(列名)的所有表
SELECT TABLE_NAME '表名',TABLE_SCHEMA '数据库名',ORDINAL_POSITION '顺序',COLUMN_NAME '字段',DATA_TYPE '类型' ,CH ...