比赛 |
20120619 |
评测结果 |
AAAAAAAAAA |
题目名称 |
隐藏的信息 |
最终得分 |
100 |
用户昵称 |
Fmuckss |
运行时间 |
0.016 s |
代码语言 |
C++ |
内存使用 |
0.31 MiB |
提交时间 |
2016-04-22 11:07:02 |
显示代码纯文本
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long LL;
bool use[10];
int out[10];
int n, judge;
int p, q;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b); }
int get_line(bool *a) {
int i = 0;
char tmp = getchar();
while(tmp < '0' || tmp > '9') tmp = getchar();
while(tmp <= '9' && tmp >= '0') {
a[tmp - '0'] = false;
tmp = getchar();
i++;
}
return i;
}
bool ans;
void dfs(int now, LL num) {
if(now == n+1) {
if(num % judge) return;
ans = true;
printf("%lld\n", num);
return;
}
for(int i = 1; i <= n; i++) {
if(use[out[i]]) continue;
use[out[i]] = true;
dfs(now+1, num*10 + out[i]);
use[out[i]] = false;
}
}
void read() {
for(int i = 1; i <= 9; i++) use[i] = true;
n = get_line(use);
scanf("%d %d", &p, &q);
}
void handle() {
judge = p;
for(int i = p+1; i <= q; i++) {
int tmp = gcd(judge, i);
judge = (judge * i)/tmp;
}
int cnt = 0;
for(int i = 1; i <= 9; i++) {
if(use[i]) continue;
out[++cnt] = i;
}
}
void solve() {
ans = false;
dfs(1, 0);
if(!ans) printf("No answer\n");
}
int main() {
freopen("lcsa.in", "r", stdin);
freopen("lcsa.out", "w", stdout);
read();
handle();
solve();
return 0;
}