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的更多相关文章

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

  2. (Problem 33)Digit canceling fractions

    The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...

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

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

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

  6. (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, ...

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

  8. (Problem 70)Totient permutation

    Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...

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

随机推荐

  1. 关于tableView的简单实例

    关于tableCell选中颜色 //无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色 cell.selectionSty ...

  2. DataSet - DataTable - DataRow 读取 xml 文件 + 搜索

    DataSet ds = XmlHelper.GetDataSetByXml(AppDomain.CurrentDomain.BaseDirectory + "/Config/ConfigN ...

  3. w3c教程

    http://www.w3cfuns.com/course.php http://www.w3cfuns.com/home.php?mod=space&uid=5434413&do=b ...

  4. HTML5入门(一)

    HTML简单介绍: HTML(HyperText Markup Language),超文本标记语言,是一种专门用于创建web的超文本文档编程语言,是我们看到的网页的源代码. 版本简介: 1997年推出 ...

  5. EF的泛型封装 写的很好 转自Fly_Elephant http://www.cnblogs.com/xiaofeixiang/p/4188600.html?utm_source=tuicool

    Entity Framework本身的增删改查其实 已经很方便了,不过做项目的时候用的多了也就觉得有点累了,每个业务实体基本上都涉及到到了增删改查这四个基本的要素,至于封装每个公司可能都不一样,接口, ...

  6. GBK转utf-8,宽字符转窄字符

    //GBK转UTF8 string CAppString::GBKToUTF8(const string & strGBK) { string strOutUTF8 = "" ...

  7. 类中成员函数与数据成员private/pubic/protected

    类中成员函数与数据成员private/pubic/protected

  8. #ifndef 与 #program once 的区别(转)

    转自http://hi.baidu.com/hrx20091001/item/ee70f7cc6d036d4ea9ba94e0 #ifndef 与 #program once 的区别 为了避免同一个文 ...

  9. 打印 PHP $_SERVER 常量

    foreach( $_SERVER as $var => $value){ echo $var.' '.$value.'<br>'; };

  10. A Byte of Python 笔记(6)模块

    第8章 模块 用户在程序中定义一次函数而重用代码,如果用户想在其他程序中重用很多函数,可以通过使用模块的方式. 模块就是一个包含了所有用户定义的函数和变量的文件.为了在其他程序中重用模块,模块的文件名 ...