从大到小排序,相邻两项作差,求gcd,如果K是gcd的倍数并且K<=max{a(i)},必然有解,否则无解. 可以自己手画画证明. #include<cstdio> #include<algorithm> using namespace std; int n,K,a[100010]; int main(){ scanf("%d%d",&n,&K); for(int i=1;i<=n;++i){ scanf("%d"…
#include<stdio.h> int gcd(int a, int b) { int c; while(b) { c = a % b; a = b; b = c; } return a; } int main() { int a, b; while(scanf("%d%d", &a, &b) != EOF) { printf("%d\n", gcd(a, b)); } ; }…