POJ 3970(最小公倍数LCM)
版权声明:Site:https://skyqinsc.github.io/ https://blog.csdn.net/u013986860/article/details/26182055
知识点:
最小公倍数(a,b)=a*b/最大公约数(a。b)
Party
Description
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
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
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)的更多相关文章
- 1012 最小公倍数LCM
1012 最小公倍数LCM 基准时间限制:1 秒 空间限制:131072 KB 输入2个正整数A,B,求A与B的最小公倍数. Input 2个数A,B,中间用空格隔开.(1<= A,B < ...
- 最大公约数(GCD)与最小公倍数(LCM)的计算
给出两个数a.b,求最大公约数(GCD)与最小公倍数(LCM) 一.最大公约数(GCD) 最大公约数的递归: * 1.若a可以整除b,则最大公约数是b * 2.如果1不成立,最大公约数便是b ...
- POJ 2429 GCD & LCM Inverse(Pollard_Rho+dfs)
[题目链接] http://poj.org/problem?id=2429 [题目大意] 给出最大公约数和最小公倍数,满足要求的x和y,且x+y最小 [题解] 我们发现,(x/gcd)*(y/gcd) ...
- [POJ 2429] GCD & LCM Inverse
GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10621 Accepted: ...
- ACM数论之旅3---最大公约数gcd和最小公倍数lcm(苦海无边,回头是岸( ̄∀ ̄))
gcd(a, b),就是求a和b的最大公约数 lcm(a, b),就是求a和b的最小公倍数 然后有个公式 a*b = gcd * lcm ( gcd就是gcd(a, b), ( •̀∀•́ ) ...
- 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 ...
- 最大公约数gcd、最小公倍数lcm
最大公约数(辗转相除法) 循环: int gcd(int a,int b) { int r; ) { r=b%a; b=a; a=r; } return b; } 递归: int gcd(int a, ...
- 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 ...
- 最大公约数gcd与最小公倍数lcm
最大公约数:gcd 最大公倍数:lcm gcd和lcm的性质:(我觉得主要是第三点性质) 若gcd (
随机推荐
- sqlserver 2008R2新建数据库时报错,提示无法获得数据库"model"上的排它锁
刚新装了个sqlserver2008 R2,在建立数据库时候报错,提示无法获得数据库"model"上的排它锁.解决办法如下: 打开查询页面,执行下面的语句即可. use maste ...
- Could not get JDBC connection
想学习下JavaWeb,手头有2017年有活动的时候买的一本书,还是全彩的,应该很适合我这种菜鸟技术渣. 只可惜照着书搭建了一套Web环境,代码和db脚本都是拷贝的光盘里的,也反复检查了数据库的连接情 ...
- Module的加载实现
烂笔头开始记录小知识点啦- 浏览器要加载 ES6模块,: <script type="module" src="./foo.js"></scr ...
- linux mail操作
本操作系统邮件由来,crontab定时任务执行推送产生. 1.查看有多少封邮件 & file 2.我们直接键入23935来访问这封mail,看看是否是我们所需要的最新邮件. 3. 退出邮件查看 ...
- 2:Python字符串与数字
字符串(引号):只有四种情况如下 name="我是编程高手" name='我是编程高手' name="""我是编程高手""&quo ...
- sublime text2 中标签高亮效果BracketHighlighter插件
1.打开package Control,选择install Package 2.输入BracketHighlighter,回车 3.这样该插件会自动安装,安装后所有的提示高亮都是白色或没有提示.按 p ...
- BZOJ2434: [Noi2011]阿狸的打字机(AC自动机 树状数组)
Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4140 Solved: 2276[Submit][Status][Discuss] Descript ...
- 中国 AI 天才养成计划:清华姚班和 100 个「张小龙」
https://daily.zhihu.com/story/9653612?from=timeline&isappinstalled=0 AI财经社,专注未来,以及更好的生活 真正的 AI ...
- drawable自定义字体颜色
一个很基础简单的问题,但是以前没用过,都是代码控制效果的,最近新的项目发现设置了color属性没效果,后来查了会资料才发现得单独设置,记录一下,虽然是小问题 上面的xml控制背景的变化,一开始我设置在 ...
- ReactNative编写规范
<一> React 代码规范 文件与组件命名 扩展名: 使用.js作为js文件的扩展名.如果同一个文件夹下有同名而不同作用的js文件,则通过中缀(小写)进一步区分,例如:HomePage ...