POJ 3970(最小公倍数LCM)
来源:互联网 发布:误入传销 知乎 编辑:程序博客网 时间:2024/06/17 12:37
知识点:
最小公倍数(a,b)=a*b/最大公约数(a,b)
Party
Description
The CEO of ACM (Association of Cryptographic Mavericks) organization has invited all of his teams to the annual all-hands meeting, being a very disciplined person, the CEO decided to give a money award to the first team that shows up to the meeting.
The CEO knows the number of employees in each of his teams and wants to determine X the least amount of money he should bring so that he awards the first team to show up such that all team members receive the same amount of money. You must write a program to help the CEO achieve this task.
The CEO knows the number of employees in each of his teams and wants to determine X the least amount of money he should bring so that he awards the first team to show up such that all team members receive the same amount of money. You must write a program to help the CEO achieve this task.
Input
The input consists of multiple test cases, each test case is described on a line by itself, Each line starts with an integer N (1 <= N <= 20) the number of teams in the organization followed by N space separated positive integers representing the number of employees in each of the N teams. You may assume that X will always fit in a 32 bit signed integer. The last line of input starts with 0 and shouldn't be processed.
Output
For each test case in the input print "The CEO must bring X pounds.", where X is as described above or "Too much money to pay!" if X is 1000000 or more.
Sample Input
1 30000002 12 40
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;}
0 0
- POJ 3970(最小公倍数LCM)
- LCM Challenge(最小公倍数)
- Lcm(最小公倍数)
- hdu 1019 最小公倍数(LCM)
- hdoj1108最小公倍数(GCD,LCM)
- 最小公倍数LCM
- 最小公倍数(LCM)与最大公约数(GCD)
- gcd(最大公因数) && lcm(最小公倍数)
- 求N个数的最小公倍数(LCM)
- 杭电-1108 最小公倍数 (LCM&GCD)
- 最大公约数与最小公倍数(gcd,lcm)
- 51Nod1012 最小公倍数LCM(C语言)
- 最大公约数gcd&最小公倍数lcm
- HDU 1108 最小公倍数(lcm)
- HDU 1108 最小公倍数【lcm】
- 最小公倍数 LCM 1
- 最小公倍数 LCM 2
- 计算最小公倍数LCM
- 模式匹配KMP POJ2752
- PAT Advanced Level 1018
- 黑马程序员_笔迹四_面向对象(基础)
- android adb读写挂载跟目录
- 黑马程序员_笔记五_面向对象(高级)
- POJ 3970(最小公倍数LCM)
- 黑马程序员----------java基础加强之多线程、单例设计模式
- 黑马程序员_笔记六_面向对象(高级)---抽象类
- 黑马程序员_笔迹七_面向对象(高级)---接口
- c3p0三种配置方式
- 一个空间如何绑定多个域名:[1]IIS绑定
- 黑马程序员_笔迹八_关于代码块
- 黑马程序员_笔迹九_关于Object类和包装类
- c#代理的作用