-
Notifications
You must be signed in to change notification settings - Fork 0
/
p43.cpp
55 lines (49 loc) · 1005 Bytes
/
p43.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
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
bool isPan(long x, int n)
{
unsigned int d[n+2];
int len = (int)log10(x)+1;
if (len != n+1)
return false;
for (int i = 0; i <= n; i++)
d[i]=0;
for (int i = 0; i <= n; i++)
{
int index = x % 10;
if (d[index] != 0)
return false;
d[index]++;
x /= 10;
}
return true;
}
bool satisfy(long x)
{
long test = x % 1000;
int divis[] = {17,13,11,7,5,3,2};
for (int i = 0; i < 7; i++)
{
if (test % divis[i] != 0)
return false;
x /= 10;
test = x % 1000;
}
return true;
}
int main()
{
int list[] = {1,2,3,4,5,6,7,8,9};
long sum = 0;
for (long t = 123456789; t <= 9876543210; t++)
{
if (satisfy(t) && isPan(t,9))
{
sum += t;
}
}
cout << sum << endl;
return 0;
}