-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem52.cpp
57 lines (44 loc) · 918 Bytes
/
problem52.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <map>
#include <vector>
using namespace std;
using long_t = unsigned long long ;
vector<long_t> num2vec(long_t a)
{
vector<long_t> digits;
while (a){
digits.push_back(a%10);
a /= 10;
}
return digits;
}
bool checkNums(long_t x, long_t x2, long_t x3, long_t x4, long_t x5)
{
map<long_t, bool> digits;
auto v = num2vec(x);
for ( auto d:v ){digits[d] = true;}
auto v2 = num2vec(x2);
auto v3 = num2vec(x3);
auto v4 = num2vec(x4);
auto v5 = num2vec(x5);
for (auto d:v2){ if (!digits[d]) return false;}
for (auto d:v3){ if (!digits[d]) return false;}
for (auto d:v4){ if (!digits[d]) return false;}
for (auto d:v5){ if (!digits[d]) return false;}
return true;
}
int main()
{
long_t x = 125874;
while (true){
long_t x2 = 2*x;
long_t x3 = 3*x;
long_t x4 = 4*x;
long_t x5 = 5*x;
if (checkNums(x,x2,x3,x4,x5)){
cout<<x<<endl;
break;
}
x++;
}
}