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

  1. Project Euler:Problem 33 Digit cancelling fractions

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

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

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

  4. Project Euler:Problem 55 Lychrel numbers

    If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...

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

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

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

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

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

随机推荐

  1. getActivity nullPointerException

    今天突然出现一个问题. Fragment中getActivity突然不能了,会出现空指针问题.最后也不知道是什么原因引起的. 解决的方法: @Override public void onAttach ...

  2. Nginx 内嵌lua脚本,结合Redis使用

    0x00 Nginx 内嵌Lua脚本有下面特点: 20k个并发连接 Lua脚本能够在Nignx 11个层次的不同层次发挥作用,扩展Ngnix功能 Lua速度极快(寄存器指令) 0x01 应用场景 在w ...

  3. STL - 函数作为算法的参数

    函数作为参数,相当于C++的函数指针, C#的委托 for_each函数参数: #include <iostream> #include <algorithm> #includ ...

  4. FFMPEG中最要害的结构体之间的关系

    FFMPEG中最关键的结构体之间的关系 http://www.myexception.cn/program/1404591.html FFMPEG中结构体很多.最关键的结构体可以分成以下几类: a)  ...

  5. xcode 模拟器,文档,离线安装

    一:xcode上的模拟器,文档,在下载时,通过apple.com下载的速度太慢了,所以我们下载之后,做一下备份,离线安装还原就行了! 二:模拟器安装 目录:/Users/<user name&g ...

  6. shareSDK(分享第三方库)的 使用

    首先,下载第三方库,可以去官网下载,官网的地址我忘记了,但下面有一个我之前下的和我写的例子,其实官方的例子也写我们只是告诉大家用时需要把哪些代码复制出来就可以用了. 1.导入如下框架和第三方库 新浪微 ...

  7. ZooKeeper安装方法具体解释

    ZooKeeper安装方式分为两种,一种为单机模式.一个为集群模式,集群模式须要事先正确配置hadoop集群,安装方法參考hadoop-1.2.1安装方法具体解释 单机模式安装: 1.上传并解压zoo ...

  8. APACHE + LDAP 的权限认证配置方法

    原文地址:http://www.chinaunix.net/jh/49/627646.html 一.前言 很多朋友希望利用 Apache 通过 LDAP 进行用户认证及权限管理.     通过多次试验 ...

  9. sphinx相关文章

    sphinx配置文件详解http://yanue.net/post-129.html Sphinx+Scws 搭建千万级准实时搜索&应用场景详解 http://blog.csdn.net/pi ...

  10. FFmpeg 如何探测网络流格式/如何从内存中获取数据

    文章转自:http://blog.csdn.net/rootusers/article/details/42551935 一般ffmpeg都是直接从文件中读取或者从网络流中读取,比如rtp://xx. ...