-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUVa-725.cpp
More file actions
54 lines (43 loc) · 1.11 KB
/
UVa-725.cpp
File metadata and controls
54 lines (43 loc) · 1.11 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
#include <iostream>
#include <vector>
#include <algorithm>
#define FAST std::cin.tie(0); ios::sync_with_stdio(false); std::cout.tie(0);
using namespace std;
void solve(int n);
int main() {
FAST
int n;
bool first = true;
while (scanf("%d", &n) && n) {
if (!first) {
cout << "\n";
}
first = false;
getchar();
solve(n);
}
}
void solve(int n) {
bool found = false;
for (int first = 1234; first <= 98765 / n; ++first) {
int second = first * n;
int digits = (first < 10000); // Check if a leading zero is needed for the first number
int tmp = second;
while (tmp) {
digits |= 1 << (tmp % 10);
tmp /= 10;
}
tmp = first;
while (tmp) {
digits |= 1 << (tmp % 10);
tmp /= 10;
}
if (digits == (1 << 10) - 1) {
found = true;
cout << second << " / " << (first < 10000 ? "0" : "") << first << " = " << n << "\n";
}
}
if (!found) {
cout << "There are no solutions for " << n << ".\n";
}
}