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 ...
随机推荐
- 项目笔记:创建XML文件和导出功能
一.创建XML文件: 要生成的XML结构: //创建文件夹 private void createFilePah(String path){ File file = new File(path); i ...
- OpenGL入门学习(转载)
说起编程作图,大概还有很多人想起TC的#include <graphics.h>吧? 但是各位是否想过,那些画面绚丽的PC游戏是如何编写出来的?就靠TC那可怜的640*480分辨率.16色 ...
- 转:mac下安装Sublime Text
转:http://blog.sina.com.cn/s/blog_559d66460101cab0.html 正版的买个license其实并不贵,定价为70美元.如果不买license,也可acces ...
- (LeetCode 49)Anagrams
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...
- C++ 中特殊的用法
1.反斜杠 a.转义字符 b.强制换行,当一行代码很长时,在这一行中间加上反斜杠,分成两行,反斜杠前后不能有空格.在预编译的的时候,会合成一行. 2.String^ 表明String是一个托管类型的指 ...
- Android调用OCR识别图像中的文字
// CharacterExtractor.java // Copyright (c) 2010 William Whitney // All rights reserved. // This sof ...
- Linux 监测CPU常用的工具sar iostat vmstat top uptime
sar -u 1 2 iostat -c 1 2 vmstat 1 2 top uptime Linux监控CPU整体性能常用的工具有: # mpstat: mpstat 不但能查看所有CPU的平均信 ...
- java反射--通过反射了解集合泛型的本质
通过Class,Method来认识泛型的本质 package com.reflect; import java.lang.reflect.Method; import java.util.ArrayL ...
- jenkins+gitlab钩子+shell脚本基于git的tag实现App增量更新
转自:http://blog.csdn.net/kingboyworld/article/details/54175330 环境安装 jdk1.8 1.安装jenkins 首先到https://jen ...
- VS2012不能创建数据库连接出现或者连接数据库时提示:未能载入文件或程序集“Microsoft.SqlServer.Management.Sdk.Sfc, Version=10.0.0.0, C
VS2012不能创建数据库连接时或者连接数据库时提示:未能载入文件或程序集"Microsoft.SqlServer.Management.Sdk.Sfc, Version=10.0.0.0, ...