HDU—— 1019 Least Common Multiple
来源:互联网 发布:英国脱离欧盟 知乎 编辑:程序博客网 时间:2024/05/22 07:51
题意:求一组数的最小公倍数。
解题思路:最小公倍数与最大公约数的乘积等于这两个数的乘积,利用结论可较快求出答案,详见代码。
#include <iostream>#include <cstdio>using namespace std;int GCD(int a,int b){ return b==0 ? a:GCD(b,a%b);}int LCM(int a,int b){ return a/GCD(a,b)*b;}int main(){ int T,N,a,b; scanf("%d",&T); getchar(); while(T--) { scanf("%d%d",&N,&a); int temp = a; for(int i = 1; i<N; i++) { scanf("%d",&b); temp = LCM(temp,b); } printf("%d\n",temp); } return 0;}
0 0
- HDU—— 1019 Least Common Multiple
- 1019—Least Common Multiple
- 【HDU 1019】Least Common Multiple —— LCM
- HDU 1019 Least Common Multiple
- hdu 1019 Least Common Multiple
- HDU-1019 least common multiple
- HDU 1019 Least Common Multiple
- HDU 1019 Least Common Multiple
- HDU 1019 Least Common Multiple
- HDU 1019 Least Common Multiple
- hdu 1019Least Common Multiple
- hdu 1019 Least Common Multiple
- hdu 1019 Least Common Multiple
- Hdu 1019 Least Common Multiple
- hdu 1019 Least Common Multiple
- HDU 1019Least Common Multiple
- hdu 1019 Least Common Multiple
- hdu 1019 Least Common Multiple
- 分布式事务
- oracle共享服务器模式配置
- iOS学习笔记(十六)——数据库操作(使用FMDB) .
- nodejs中Async库介绍
- 1411211846-hd-Big Event in HDU
- HDU—— 1019 Least Common Multiple
- Java面试题:请说说MVC架构
- 关联矩阵
- 单调递增最长子序列(南阳oj17)(经典dp)
- (C)const关键字
- POJ1573 - Robot Motion
- JSP作用域之pageContext,request,session,application
- 梵蒂冈的鬼地方个地方
- 2014年工作中遇到的20个问题:101-120