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. 解决eclipse中运行web项目时弹出的"Port 8080 required by Tomcat 9.0 Server at localhost is already in use...

    1.tomcat默认端口是8080,可以修改通过tomcat的端口 修改tomcat\conf\server.xml     结果运行程序,还是报"Port 8080 required by ...

  2. SpringSecurity实现后台管理员登录(二)

    需求:login.ftl页面中登录成功后进入index.ftl页面中 一.pom.xml中添加json转换相关的包 <dependency> <groupId>com.fast ...

  3. C#应用视频教程1.4 实现完整以太网通讯

    对于事件和委托机制不够理解的读者可以参考本节提供的委托相关的范例程序,这个是控制台的程序,比较简洁(书店发布一本书的事件注册到某个读者A身上,原理跟前面一小节讲的是一致的,只不过没有通过委托对外发送数 ...

  4. Apache多站点配置教程

    看见这个版关于网络程序方面的文章还比较少,下面来一发~实践证明,本教程适用于Apache 2.2.22,其他版本相差应该不大 我的博客:http://wislab.net/,希望跟大家多多交流噢 Ap ...

  5. selenium 问题:OSError: [WinError 6] 句柄无效

    问题: 执行多个用例的时候,会抛出异常: File "xxxxxx.py", line 16, in get_driver driver = webdriver.Chrome(ex ...

  6. Android SDK镜像的介绍使用【转发】

    由于一些原因,Google相关很多服务都无法访问,所以在很多时候我们SDK也无法升级,当然通过技术手段肯定可以解决,但是比较麻烦,而且下载速度也不怎么样. 这里笔者介绍一个国内的Android镜像站, ...

  7. DBMS_METADATA中使用SESSION_TRANSFORM过滤不想获取的DDL

    我们一般使用dbms_metadata.get_ddl获取对象的ddl的时候,有时会获取一些其它额外的信息,比如当你想获取表的创建语句的时候,你会得到表的约束信息,这个信息可能是你不想要的,那么就能够 ...

  8. JDBC JdbTemplate&NamedParameterJdbcTemplate(Spring工具类)

    使用该工具类需要从spring开发包中导入spring.jar和commons-logging.jar,这个模板是线程安全的.   JdbcTemplate: public class JdbcTem ...

  9. 【转帖】Dubbo:来自于阿里巴巴的分布式服务框架

    http://www.biaodianfu.com/dubbo.html Dubbo是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被 ...

  10. TCP的发送缓冲区和接收缓冲区

    TCP协议是作用是用来进行端对端数据传送的,那么就会有发送端和接收端,在操作系统有两个空间即user space和kernal space. 每个Tcp socket连接在内核中都有一个发送缓冲区和接 ...