您的位置:首页 > 大数据 > 人工智能

HDU 1788 Chinese remainder theorem again

2014-08-11 10:38 567 查看
题目链接

题意 : 中文题不详述。

思路 : 由N%Mi=(Mi-a)可得(N+a)%Mi=0;要取最小的N即找Mi的最小公倍数即可。

//1788
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#define LL long long

using namespace std ;

LL gcd(LL x,LL y)
{
return y == 0 ? x : gcd(y,x%y) ;
}
int main()
{
int I,a ;
while(~scanf("%d %d",&I,&a))
{
if(I == 0 && a == 0) break ;
int x ;
LL ans = 1;
while(I--)
{
scanf("%d",&x) ;
ans = (ans * x)/gcd(ans,x) ;
}
printf("%I64d\n",ans-a) ;
}
return 0 ;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: