forked from wandering007/ProjectEuler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP52.cpp
More file actions
80 lines (76 loc) · 1.41 KB
/
P52.cpp
File metadata and controls
80 lines (76 loc) · 1.41 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<iostream>
#include<fstream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iomanip>
#define MAXN 10000000
#define LL long long
#define eps 1e-6
#define inf 0x3f3f3f3f
using namespace std;
int len;
void ToString(LL n, int* s)
{
len = 0;
while(n)
{
s[++len] = n % 10;
n /= 10;
}
return;
}
bool compare(int* s1, int* s2)
{
for(int i = 1; i <= len; i++)
if(s1[i] != s2[i])
return false;
return true;
}
bool isFound(LL n)
{
int s1[20], s2[20];
ToString(n, s1);
sort(s1 + 1, s1 + len + 1);
for(int i = 2; i <= 6; i++)
{
ToString(n * i, s2);
sort(s2 + 1, s2 + len + 1);
if(!compare(s1, s2))
return false;
}
return true;
}
int main()
{
double duration;
clock_t start = clock();
for(LL i = 1LL, l = 10; ; i++)
{
if(i * 6 >= l)
{
i = l;
l *= 10;
continue;
}
if(isFound(i))
{
printf("%I64d\n", i);
break;
}
}
duration = (clock() - start) / CLOCKS_PER_SEC;
printf("time cost: %f\n", duration);
return 0;
}