题意:给定 n 个数,一个数 k,然后你知道一个数 x 取模这个 n 个的是几,最后问你取模 k,是几。
析:首先题意就看了好久,其实并不难,我们只要能从 n 个数的最小公倍数是 k的倍数即可,想想为什么。如果考虑用 k 除以最大公约数是错误的,
因为可能存在相同的因数,这个是不能算的。
代码如下:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }//最大公约数
LL lcm(LL a, LL b){ return a * b / gcd(a, b); }//最小公倍数
int main(){
int n; LL k, x;
scanf("%d %lld", &n, &k);
LL ans = 1;
for(int i = 0; i < n; ++i){
scanf("%lld", &x);
ans = lcm(ans, x) % k;
}
if(!ans) puts("Yes");//如果能整除就是可以的
else puts("No");
return 0;
}
浙公网安备 33010602011771号