标签:output class fine 有一个 mat 过程 iostream space out
Input输入数据包含多组测试实例,每个实例的第一行是两个整数I(1<I<10)和a,其中,I表示M的个数,a的含义如上所述,紧接着的一行是I个整数M1,M1...MI,I=0 并且a=0结束输入,不处理。
Output对于每个测试实例,请在一行内输出满足条件的最小的数。每个实例的输出占一行。
Sample Input
2 1 2 3 0 0
Sample Output
5
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#define N 1000010
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/gcd(a,b)*b;
}
int main()
{
ll n,y,m;
while(~scanf("%lld%lld",&n,&y),n&&y)
{
ll ans=1;
for(int i=0;i<n;i++)
{
scanf("%lld",&m);
ans=lcm(m,ans);
}
cout<<ans-y<<endl;
}
}
hdu_1788_Chinese remainder theorem again (lcm
标签:output class fine 有一个 mat 过程 iostream space out
原文地址:http://www.cnblogs.com/ygtzds/p/7900478.html