poj 3970 Party 最小公倍数

来源:互联网 发布:linux 挂载有数据硬盘 编辑:程序博客网 时间:2024/06/05 02:25

题意:

给n个数,求它们的最小公倍数。

分析:

lcm(a,b)==a*b/gcd(a,b);

代码:

//poj 3970//sep9#include <iostream>using namespace std;typedef long long ll;ll gcd(ll a,ll b){return a%b==0?b:gcd(b,a%b);}int main(){int n;while(scanf("%d",&n)==1&&n){ll ans,x;scanf("%lld",&ans);--n;while(n--){scanf("%lld",&x);ans=ans*x/(gcd(ans,x));}if(ans>=1000000) puts("Too much money to pay!");else printf("The CEO must bring %lld pounds.\n",ans);}} 


0 0
原创粉丝点击