Problem 34

Problem 34

https://projecteuler.net/problem=34

145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.

145是一个神奇的数字,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.

注意:不包括1和2。

def factorial(num):
    f = 1
    for i in range(1, num+1):
        f *= i
    return f

tot = 0
nums = []
for i in range(3, 99999):
    print(i)
    digits = list(str(i))
    if i < factorial(int(max(digits))):
        continue
    multi = 0
    for digit in digits:
        multi += factorial(int(digit))
    if multi == i:
        nums.append(i)
        tot += i

print(nums)
print(tot)

原文地址:https://www.cnblogs.com/noonjuan/p/11031246.html

时间: 2024-11-08 10:35:34

Problem 34的相关文章

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

UOJ 34 FFT

链接: http://uoj.ac/problem/34 代码: 31 #include <complex> 32 typedef complex<double> E; 33 E a[MAXN], b[MAXN]; 34 int n, m; 35 36 namespace FFT { 37 const double Pi = acos(-1); 38 int rev[MAXN], L; 39 void DFT(E *a, int f) { 40 for (int i = 0; i

EularProject 34: 一个数字与他每位数的阶乘和

Digit factorials Problem 34 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. Answer:

九章算法面试题34 最长01子串

九章算法官网-原文网址 http://www.jiuzhang.com/problem/34/ 题目 有一个仅有0和1组成的01串,找到其中最长的一段子串,使得该子串中0和1的数目相等 解答 如果将0看做-1,则我们要找的子串是最长的和为0的子串.这种子串求和的问题,一般采用前缀和的方法来解决.用Sum[i]代表前i个数的和,问题的模型转换为,找到i和j,满足Sum[i] 与Sum[j]相等,且|i-j|最大.使用Hash表作为辅助数据结构,Hash表中记录了获得某个Sum时最小的i.从左到右遍

●UOJ 34 多项式乘法

题链: http://uoj.ac/problem/34 题解: FFT入门题. (终于接触到迷一样的FFT了) 初学者在对复数和单位根有简单了解的基础上,可以直接看<再探快速傅里叶变换>(毛啸). (主要用于求两个序列的卷积) 代码: 递归版: #include<bits/stdc++.h> #define MAXN 300000 using namespace std; const double Pi=acos(-1); struct Z{ double real,image;

【uoj34】 多项式乘法

http://uoj.ac/problem/34 (题目链接) 题意 求两个多项式的乘积 Solution 挂个FFT板子.当然,是hzwer的板子→_→ 细节 FFT因为要满足n是2的幂,所以注意数组大小. 代码 // uoj34 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<complex> #include<cst

算法导论学习-子数组最大和问题

1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 const int maxsize=101; 5 int a[maxsize],sum[maxsize],n,inf=(1<<30); 6 void solve(){ 7 if(n==0) return; 8 int ans=-inf; 9 sum[1]=a[1]; 10 int left=1,right=1; 11 for(int i

liblinear参数及使用方法(原创)

开发语言:JAVA 开发工具:eclipse (下载地址 http://www.eclipse.org/downloads/) liblinear版本:liblinear-1.94.jar (下载地址:http://liblinear.bwaldvogel.de/) 更多信息请参考:http://www.csie.ntu.edu.tw/~cjlin/liblinear/ 1.下载 liblinear-1.94.jar,导入工程 在工程上右键---->Properties----->选中Java

projecteuler----&gt;problem=34----Digit factorials

Problem 34 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. puts (0..50000).select{|