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. mysql的正则表达式

    所谓正在表达式,就是通过模式去匹配一类字符串.MySQL支持的模式字符如下表所示: MySQL支持的模式字符 模式字符 含义 ^ 匹配字符串的开始部分 $ 匹配字符串的结束部分 . 匹配字符串中的任意 ...

  2. text-overflow样式属性值ellipsis的用法

            一.div标签中使用text-overflow样式属性值ellipsis的方法: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1. ...

  3. Hidden Markov Model Toolbox for Matlab

    官网:http://www.cs.ubc.ca/~murphyk/Software/HMM/hmm.html Download Click here. Unziping creates a direc ...

  4. Oracle DB 复制数据库

    • 列出创建副本数据库的目的 • 选择用于复制数据库的方法 • 使用RMAN 复制数据库 • 使用RMAN 备份复制数据库 • 基于正在运行的实例复制数据库 使用副本数据库 • 使用副本数据库可执行以 ...

  5. [Exception JavaWeb 1] - javax.el.PropertyNotFoundException: Property 'id' not found on ..........

    好久不写Web应用了,今天碰到这个问题的时候,还一时半会没反应过来.实体类在jsp无法找对应的值. 最后发现是实体bean的属性的开头字母不能与次字母不能大写+小写或小写+大写,最后改成小写+小写就好 ...

  6. 使用overflow:hidden处理元素溢出和坍塌

    溢出 css溢出示意如图,子元素(背景为粉色)的长度或宽度超出父元素(背景为绿色). 通过为父元素赋 overflow:hidden 样式可将子元素超出父元素的部分隐藏起来. 也可为父元素赋 over ...

  7. 【LeetCode】94. Binary Tree Inorder Traversal (3 solutions)

    Binary Tree Inorder Traversal Given a binary tree, return the inorder traversal of its nodes' values ...

  8. Android--全局变量 很好很强大

    As you know, each Activity is also a Context, which is information about its execution environment i ...

  9. [Asp.net]IIS经典和继承模式

    引言 由于要在客户那里部署项目,就研究了一下IIS中的集成和经典模式,这里做一些笔记.希望对您有所帮助. IIS7.0和IIS6.0 IIS7.0的web应用程序有两种配置模式:经典模式和集成模式.经 ...

  10. 不止是联网!教你玩转PC自带Wi-Fi网卡

    前言:Wi-Fi对于现在的智能手机来说已经是再熟悉不过的配置了,而主板自带Wi-Fi网卡的设计也越来越普及,但有些玩家可能思维还停留在“Wi-Fi网卡 = 连无线网络用的网卡,我用有线就不需要”的层次 ...