-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path32.cpp
55 lines (51 loc) · 1.04 KB
/
32.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 <cstdio>
#include <vector>
#include <unordered_set>
bool test(int a, int b, int c){
int i = (1 << 9) - 1;
// printf("%d\n", i);
std::vector<int> xs = {a, b, c};
for (auto x : xs) {
// printf("%d\n", x);
while (x != 0) {
if (x % 10 == 0) return false;
int j = 1 << ((x % 10) - 1);
// printf("%d ", j);
if ((i & j) == 0) return false;
i ^= j;
x /= 10;
}
// printf("\n");
}
// printf("%d\n", i);
return i == 0;
}
int main() {
// can only be 1 digit * 4 digit = 4 digit
// or 2 digit * 3 digit = 4 digit
// test(39, 186, 7254);
// return 0;
std::unordered_set<int> ans;
for (int a = 1; a < 10; ++a) {
for (int b = 1000; b < 10000; ++b) {
int c = a * b;
if (test(a, b, c)) {
printf("%d * %d = %d\n", a, b, c);
ans.insert(c);
}
}
}
for (int a = 10; a < 100; ++a) {
for (int b = 100; b < 1000; ++b) {
int c = a * b;
if (test(a, b, c)) {
printf("%d * %d = %d\n", a, b, c);
ans.insert(c);
}
}
}
int sum = 0;
for (auto &x : ans) sum += x;
printf("%d\n", sum);
return 0;
}