forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3457 - Absence Number.cpp
73 lines (49 loc) · 1.25 KB
/
3457 - Absence Number.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
bool used[76344];
int found[100];
int solve(int den){
int num = 1,last = 0,d,cont = 0;
while(num<den) num *= 10;
memset(used,false,sizeof(used));
while(cont<100){
d = num/den;
num %= den;
last = last*10+d;
if(found[last]!=den){
found[last] = den;
++cont;
}
last = d;
if(!used[num]) used[num] = true;
else{
d = (num*10)/den;
last = last*10+d;
if(found[last]!=den){
found[last] = den;
++cont;
}
break;
}
num *= 10;
}
if(cont!=99) return -1;
int ret = 0;
for(int i = 0;i<100;++i) if(found[i]!=den) ret = i;
return ret;
}
int main(){
int ans[100];
memset(ans,-1,sizeof(ans));
memset(found,-1,sizeof(found));
for(int m = 327,cont = 0,n;m<=76344;++m){
n = solve(m);
if(n!=-1 && ans[n]==-1) ans[n] = m;
}
int N;
while(scanf("%d",&N)==1)
printf("%d\n",ans[N]);
return 0;
}