注解
1、分析后得知,本题是求n个数的最小公倍数,然后再减去a即可。
2、最小公倍数等于两数的乘积除以其最大公约数。
代码
#include <iostream>
#include <cstring>
using namespace std;
typedef long long int LL;
LL gcd(LL m, LL n){
while(m%n){
LL t = m;
m = n;
n = t%n;
}
return n;
}
int main() {
int I, a;
cin>>I>>a;
while(I || a){
LL b[I];
memset(b, 0, sizeof(b));
LL ans = 1;
for(int i=0; i<I; i++){
cin>>b[i];
ans = ans*b[i]/gcd(ans, b[i]);
}
ans -= a;
cout<<ans<<endl;
cin>>I>>a;
}
return 0;
}