版权声明:Site:https://skyqinsc.github.io/ https://blog.csdn.net/u013986860/article/details/26182055



知识点:

     最小公倍数(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.

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 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;
}

POJ 3970(最小公倍数LCM)的更多相关文章

  1. 1012 最小公倍数LCM

    1012 最小公倍数LCM 基准时间限制:1 秒 空间限制:131072 KB 输入2个正整数A,B,求A与B的最小公倍数. Input 2个数A,B,中间用空格隔开.(1<= A,B < ...

  2. 最大公约数(GCD)与最小公倍数(LCM)的计算

    给出两个数a.b,求最大公约数(GCD)与最小公倍数(LCM) 一.最大公约数(GCD)    最大公约数的递归:  * 1.若a可以整除b,则最大公约数是b  * 2.如果1不成立,最大公约数便是b ...

  3. POJ 2429 GCD & LCM Inverse(Pollard_Rho+dfs)

    [题目链接] http://poj.org/problem?id=2429 [题目大意] 给出最大公约数和最小公倍数,满足要求的x和y,且x+y最小 [题解] 我们发现,(x/gcd)*(y/gcd) ...

  4. [POJ 2429] GCD & LCM Inverse

    GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10621   Accepted: ...

  5. ACM数论之旅3---最大公约数gcd和最小公倍数lcm(苦海无边,回头是岸( ̄∀ ̄))

    gcd(a, b),就是求a和b的最大公约数 lcm(a, b),就是求a和b的最小公倍数 然后有个公式 a*b = gcd * lcm     ( gcd就是gcd(a, b), ( •̀∀•́ ) ...

  6. POJ:2429-GCD & LCM Inverse(素数判断神题)(Millar-Rabin素性判断和Pollard-rho因子分解)

    原题链接:http://poj.org/problem?id=2429 GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K To ...

  7. 最大公约数gcd、最小公倍数lcm

    最大公约数(辗转相除法) 循环: int gcd(int a,int b) { int r; ) { r=b%a; b=a; a=r; } return b; } 递归: int gcd(int a, ...

  8. POJ 2429 GCD & LCM Inverse (Pollard rho整数分解+dfs枚举)

    题意:给出a和b的gcd和lcm,让你求a和b.按升序输出a和b.若有多组满足条件的a和b,那么输出a+b最小的.思路:lcm=a*b/gcd   lcm/gcd=a/gcd*b/gcd 可知a/gc ...

  9. 最大公约数gcd与最小公倍数lcm

    最大公约数:gcd 最大公倍数:lcm gcd和lcm的性质:(我觉得主要是第三点性质) 若gcd (

随机推荐

  1. 【LInux】查看Linux系统版本信息

    一.查看Linux内核版本命令(两种方法): 1.cat /proc/version [root@S-CentOS home]# cat /proc/versionLinux version 2.6. ...

  2. virtualbox中 Ubuntu安装增强功能

    1. 执行,等待,当提示按 Enter 时按下 2. 在文件管理中找到挂载的文件,切换到该目录,执行命令 sudo ./VBoxLinuxAdditions.run 3. 重启

  3. 程序员晋级CTO之路的8大准则

    推荐阅读: 大数据智慧平台落地方案 Nginx + 阿里云SSL + tomcat 实现https访问代理 永远别忘了TD 再确认测试代码前,先找别人帮你检查下是否无误.在别人做之前尽量检查出bug并 ...

  4. spring-framework-中文文档二:Bean概述

    Spring IoC容器管理一个或多个bean.这些bean是使用您提供给容器的配置元数据创建的,例如,以XML <bean/>定义的形式 . 在容器本身中,这些bean定义被表示为 Be ...

  5. HTML笔记(适合新手入门)

    HTML Web 标准构成 Web标准不是某一个标准,而是由W3C和其他标准化组织制定的一系列标准的集合. 主要包括结构(Structure).表现(Presentation)和行为(Behavior ...

  6. CSS样式—— 字体、元素的垂直水平居中

    1.CSS样式与HTML中标签属性的区别: 标签的属性是采用 属性名=“属性值” 表示的 CSS样式是采用名值对 属性名:属性值: 表示的 2.内联元素(行内元素)与块元素 (1)内联元素及其特点: ...

  7. iOS----------导航栏的正确隐藏方式

    第一种做法 -注意这里一定要用动画的方式隐藏导航栏,这样在使用滑动返回手势的时候效果最好,和上面动图一致.这样做有一个缺点就是在切换tabBar的时候有一个导航栏向上消失的动画. - (void)vi ...

  8. Python 基于Python从mysql表读取千万数据实践

    基于Python 从mysql表读取千万数据实践   by:授客 QQ:1033553122 场景:   有以下两个表,两者都有一个表字段,名为waybill_no,我们需要从tl_waybill_b ...

  9. 性能优化4--Bitmap内存优化

    1.Bitmap在Android虚拟机中的内存分配 在Android3.0之前,Bitmap的内存分配分为两部分,一部分是分配在Dalvik的VM堆中.而像素数据的内存是分配在Native堆中,而到了 ...

  10. 【Spring源码解读】bean标签中的属性(二)你可能还不够了解的 abstract 属性和 parent 属性

    abstract 属性说明 abstract 在java的语义里是代表抽象的意思,用来说明被修饰的类是抽象类.在Spring中bean标签里的 abstract 的含义其实也差不多,表示当前bean是 ...