mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
997ec50f19
1700-1799
37 lines
563 B
C++
37 lines
563 B
C++
#include<iostream>
|
|
using namespace std;
|
|
__int64 gcd(__int64 x,__int64 y)
|
|
{
|
|
if(x<y)
|
|
{
|
|
__int64 t=x;x=y;y=t;
|
|
}
|
|
while(y!=0)
|
|
{
|
|
__int64 t=x;
|
|
x=y;
|
|
y=t%y;
|
|
}
|
|
return x;
|
|
}
|
|
__int64 work(__int64 x,__int64 y)
|
|
{
|
|
return x/gcd(x,y)*y;
|
|
}
|
|
int main()
|
|
{
|
|
__int64 n,a;
|
|
while(cin>>n>>a&&(n||a))
|
|
{
|
|
__int64 u,v;
|
|
cin>>u;
|
|
for(int i=1;i<n;i++)
|
|
{
|
|
cin>>v;
|
|
u=work(u,v);
|
|
}
|
|
cout<<u-a<<endl;
|
|
}
|
|
return 0;
|
|
}
|