知识点:
???? 最小公倍数(a,b)=a*b/最大公约数(a。b)
?????????????????????????????????????????????????????????????????????????????????????????????????????????? Party
Description
Input
Output
Sample Input
1 3000000
2 12 4
0
Sample Output
Too much money to pay!
The CEO must bring 12 pounds.
#include<iostream>
#include<cstdio>
using namespace std;
__int64 num[30];
__int64 gcd(__int64 a,__int64 b)
{
__int64 r;
__int64 t;
if(a<b)
{
t=a;
a=b;
b=t;
}
r=a%b;
while(r)
{
a=b;
b=r;
r=a%b;
}
return b;
}
__int64 lcm(__int64 a,__int64 b)
{
return a*b/gcd(a,b); //假设是int ,a*b将会溢出。造成错误
}
int main()
{
int t;
__int64 res;
while(scanf("%d",&t),t)
{
for(int i=0;i<t;i++)
scanf("%I64d",num+i);
res=num[0];
//cout<<gcd(num[0],num[0]);
for(int i=1;i<t;i++)
res=lcm(num[i],res);
if(res>=1000000)
printf("Too much money to pay!\n");
else
printf("The CEO must bring %I64d pounds.\n",res);
}
return 0;
}
原文:https://www.cnblogs.com/mqxnongmin/p/10773647.html