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 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;
}
Project Euler:Problem 34 Digit factorials的更多相关文章
- Project Euler:Problem 33 Digit cancelling fractions
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...
- Project Euler:Problem 63 Powerful digit counts
The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is ...
- Project Euler:Problem 93 Arithmetic expressions
By using each of the digits from the set, {1, 2, 3, 4}, exactly once, and making use of the four ari ...
- Project Euler:Problem 55 Lychrel numbers
If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...
- Project Euler:Problem 32 Pandigital products
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...
- Project Euler:Problem 86 Cuboid route
A spider, S, sits in one corner of a cuboid room, measuring 6 by 5 by 3, and a fly, F, sits in the o ...
- Project Euler:Problem 76 Counting summations
It is possible to write five as a sum in exactly six different ways: 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 ...
- Project Euler:Problem 87 Prime power triples
The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is ...
- Project Euler:Problem 89 Roman numerals
For a number written in Roman numerals to be considered valid there are basic rules which must be fo ...
随机推荐
- jQuery代码性能优化
代码优化是一个很重要的开发态度,一点点的优化对于程序来讲可能是微乎其微的,但是把所有的一点都加起来就能够达到水滴石穿的效果,所以要在平时的开发过程中养成优化代码的好习惯. 1. 检测元素是否存在 避免 ...
- 【云计算】Docker 镜像如何设置语言环境?bash: warning: setlocale: LC_ALL: cannot change locale (en_US)
解决方案: # set default language environment RUN locale-gen en_US.UTF- \ && dpkg-reconfigure loc ...
- 【问题】VH
[问题]: CSS中使用了VH,在iOS中展示正常,但是在安卓的个别浏览器中,当输入框弹出时,使用VH的DIV的高度会发生变化. [原因]: 在安卓端浏览器虚拟键盘弹出时,导致视口高度改变,以至于 ...
- 吐槽win7
在纠结了N次后,终于重装win7了.其间还是不死心,又找了新的xp版本来装了一下,确实不行,才心不甘情不愿地再次回到win7下. 说实话,Win7的各种新功能,我没有感觉到有多好,只有不适应,如: 资 ...
- angular中定义全局变量及全局变量的使用
一个例子,定义了两个变量,并且把变量显示出来: <!DOCTYPE html> <html ng-app="myApp"> <head> < ...
- 使用 RDVTabBarController 制作底部凸起的 TabBar 笔记
欢迎訪问我的个人博客http://mmoaay.photo/ 本文主要针对底部凸起的 TabBar 这样的特殊需求,不感兴趣的能够直接绕过- 近期做的一个项目须要底部凸起的 TabBar,效果例如以下 ...
- u32、u16、u8 数据类型
#define U32 unsigned int #define U16 unsigned short #define S32 int #define S16 short int #define U8 ...
- 聊聊高并发(二十)解析java.util.concurrent各个组件(二) 12个原子变量相关类
这篇说说java.util.concurrent.atomic包里的类,总共12个.网上有非常多文章解析这几个类.这里挑些重点说说. watermark/2/text/aHR0cDovL2Jsb2cu ...
- cocos2d-x CCScrollView 源代码分析
版本号源代码来自2.x,转载请注明 另我实现了能够循环的版本号http://blog.csdn.net/u011225840/article/details/31354703 1.继承树结构 能够看出 ...
- android中的byte数组转换(转)
/** * 将一个单字节的byte转换成32位的int * * @param b * byte * @return convert result */ public static int unsign ...