-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva725.cpp
53 lines (47 loc) · 1.2 KB
/
uva725.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
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <set>
#include <list>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
int main(int argc, char const *argv[])
{
int N;
bool firstCase = true;
while ( scanf("%d", &N) && N != 0 ) {
if ( !firstCase ) {
printf("\n");
}
bool noAnswer = true;
for (int fghij = 1234; fghij <= 98765 / N; fghij++)
{
int abcde = fghij * N;
int tmp,
used = (fghij < 10000);
tmp = abcde; while (tmp) { used |= 1 << (tmp %10); tmp /= 10; }
tmp = fghij; while (tmp) { used |= 1 << (tmp %10); tmp /= 10; }
// if all bits are on (11111111111) = 1024 then all digits have been used, print the answer
if ( used == (1<<10) - 1 ) {
printf("%0.5d / %0.5d = %d\n", abcde, fghij, N);
noAnswer = false;
}
}
if ( noAnswer )
printf("There are no solutions for %d.\n", N);
firstCase = false;
}
return 0;
}