-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem34.cpp
More file actions
40 lines (37 loc) · 1.04 KB
/
Copy pathProblem34.cpp
File metadata and controls
40 lines (37 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
Krishna Mohan
Project Euler - Problem 3
Date: 3/22/2015
*/
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for(int (i)=0;(i)<(n); (i)++)
#define MAX 999999
int main() {
int fact[10];
fill(fact, fact+10, 1);
for(int i=2;i<10;i++)
{
fact[i]=i*fact[i-1];
}
long long sum, ans=0;
for(int i=11;i<=MAX;i++)
{
sum=0;
int num=i;
while(num)
{
sum+=fact[num%10];
num/=10;
}
/*if(i==154)
cout<<"Sum: "<<sum<<endl;*/
if(sum==i)
{
//cout<<i<<endl;
ans+=i;
}
}
cout<<ans<<endl;
return 0;
}