比赛 |
202110省实验桐柏一中普及组联赛 |
评测结果 |
AAAAWAAAWA |
题目名称 |
Killer |
最终得分 |
80 |
用户昵称 |
PIG |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2021-10-18 19:35:23 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int m, n, r, gongbei = 1;
int a[105], b[105];
int gcd (int gcd_a, int gcd_b)
{
return gcd_b == 0 ? gcd_a : gcd (gcd_b, gcd_a % gcd_b);
}
bool dfs (int k, int ceng, int num)
{
if (ceng == r)
{
return 1;
}
for (int i = k + 1; i ^ m; ++i)
{
if (num % a[i] == 0 && dfs (i, ceng + 1, num / a[i]))
{
return 1;
}
}
return 0;
}
int main ()
{
freopen ("killer.in", "r", stdin);
freopen ("killer.out", "w", stdout);
scanf ("%d %d %d", &m, &n, &r);
for (int i = 0; i ^ m; ++i)
{
scanf ("%d", &a[i]);
gongbei = gongbei * a[i] / gcd (gongbei, a[i]);
}
for (int i = 0; i ^ n; ++i)
{
scanf ("%d", &b[i]);
if (b[i] % gongbei == 0)
{
printf ("%d", i + 1);
return 0;
}
}
for (int i = 0; i ^ n; ++i)
{
if (dfs (-1, 0, b[i]))
{
printf ("%d ", i + 1);
gongbei = 0;
}
}
if (gongbei)
{
printf ("0");
}
return 0;
}