-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstronnos.cpp
More file actions
45 lines (39 loc) · 925 Bytes
/
Copy pathstronnos.cpp
File metadata and controls
45 lines (39 loc) · 925 Bytes
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
41
42
43
44
45
#include <bits/stdc++.h>
using namespace std;
int factorial(int n){
int fac = 1;
for (int i = 1; i <= n; i++){
fac *= i;
}
return fac;
}
vector<int> generatestrongnos(){
vector<int> strongnumbers;
for (int i = 1; i < 10000; i++){
int temp = i;
int r, sum = 0;
while (temp > 0){
r = temp % 10;
sum += factorial(r);
temp /= 10;
}
if (sum == i){
strongnumbers.push_back(i);
}
}
return strongnumbers;
}
int main(int argc, char* argv[]){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin) ;
freopen("output.txt", "w", stdout) ;
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL) ; cout.tie(NULL) ;
vector<int> strongnumbers = generatestrongnos();
for (int x: strongnumbers){
cout << x <<endl;
}
//cout<<"hi";
return 0;
}