-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path725.cpp
36 lines (31 loc) · 947 Bytes
/
725.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
/*
brute force > iterative
difficulty: easy
date: 11/Jan/2020
by: @brpapa
*/
#include <cstdio>
#define setBit(S, i) (S |= (1 << i))
#define setAll(n) ((1 << n) - 1)
using namespace std;
int main() {
int N, T = 0;
while (1) {
scanf("%d", &N); if (N == 0) break;
if (T++ != 0) printf("\n");
bool found = false;
for (int den = 1234; den*N <= 98765; den++) {
int num = den * N;
int mask; // conjunto de bits {9, ..., 0}
mask = (den < 10000); // se tem 0 à esquerda
for (int tmp = num; tmp > 0; tmp /= 10) setBit(mask, tmp % 10);
for (int tmp = den; tmp > 0; tmp /= 10) setBit(mask, tmp % 10);
if (mask == setAll(10)) { // todos os 9 bits foram ligados
printf("%.5d / %.5d = %d\n", num, den, N);
found = true;
}
}
if (!found) printf("There are no solutions for %d.\n", N);
}
return 0;
}