Project Euler:Problem 34 Digit factorials
2024-10-19 01:33:07
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.
#include <iostream>
#include <vector>
using namespace std; vector<int> int_vet(int a)
{
vector<int> res;
while (a)
{
int tmp = a % 10;
a /= 10;
res.push_back(tmp);
}
return res;
} int a[10] = { 0 };
void p()
{
a[0] = 1;
a[1] = 1;
for (int i = 2; i <= 9; i++)
a[i] = a[i - 1] * i;
} int main()
{
p();
int res = 0;
for (int i = 3; i < 10000000; i++)
{
int count = 0;
vector<int> num = int_vet(i);
for (int j = 0; j < num.size(); j++)
count += a[num[j]];
if (count == i)
res += count;
}
cout << res << endl; system("pause");
return 0;
}
最新文章
- 删除Tomcat服务及其它注意
- 《精通C#》委托与事件(10章)
- Idea 常用快捷键列表
- RelativeLayout_布局
- 二模 (8) day1
- ASP.NET MVC5写.php路由匹配时的问题 ASP.NET MVC 4 在 .NET 4.0 与.NET 4.5 的專案範本差異
- Unity3D - Animator Controller循环依赖
- hdu 5517 Triple(二维树状数组)
- 享元模式 FlyWeight 结构型 设计模式(十五)
- docker(五) 使用Docker Registry搭建镜像私服
- JS工具类
- (链表 双指针) leetcode 19. Remove Nth Node From End of List
- RocketMQ RPC
- java框架之Spring(2)-注解配置IOC&;AOP配置
- JAVA8之函数式接口
- 【Jmeter自学】Jmeter作用域(五)
- springMVC访问 WEB-INF 下的 jsp 和 html
- .NET 互联网技术简介
- test20181223
- exp,expdb,imp,impdb的使用
热门文章
- Mongodb 常用命令2
- 字符串转成整型(int)
- PHP防抓取数据curl 解决方法
- spring autowired还需要在xml中申明bean ?
- [Algorithm -- Dynamic programming] How Many Ways to Decode This Message?
- 外媒关注:中国版Twitter新浪微博推出微米对抗微信
- 【转】DNS查询过程
- [Swift A] - A Swift Tour
- 配置tomcat的session共享
- 创建你的第一个Android PHP应用