【HDU 1019】Least Common Multiple —— LCM
来源:互联网 发布:mactype mac字体 编辑:程序博客网 时间:2024/05/01 13:12
原题链接
解题报告:
很简单的水题,就是求LCM而且指明了是在int范围内!唯一值得注意的是:lcm函数中必须先除再乘,否则有溢出的可能!
#include <iostream>using namespace std;int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b);}int lcm(int a,int b){ int GCD=gcd(a,b); if(GCD==0) return 0; return a/GCD*b; //先除再乘}int main(){ int T,n,a; int ans; cin>>T; while(T--){ cin>>n>>a; ans=a; for(int i=2;i<=n;++i){ cin>>a; ans =lcm(ans,a); } cout<<ans<<endl; }}
0 0
- 【HDU 1019】Least Common Multiple —— LCM
- hdu 1019 Least Common Multiple (水题,LCM)
- HDU - 1019 - Least Common Multiple (lcm)
- HDU—— 1019 Least Common Multiple
- 1019—Least Common Multiple
- Common Multiple and 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
- ClippingNode 实现类似子弹打穿纸片效果
- HDU 4709 三循环暴力
- Java 枚举实现单例
- IncrediBuild联合编译的使用
- 构建高性能服务(一)ConcurrentSkipListMap和链表构建高性能Java Memcached
- 【HDU 1019】Least Common Multiple —— LCM
- SVG图像动画鉴赏
- 给没有毕业的同学
- Jquery中的offset()和position()方法详解
- uiscrollview 放大/缩小后 contentSize被改变
- 二分匹配_HDU_2119
- RedHat Linux 安装oracle11g (转)
- 母牛生仔的递归算法和非递归算法。
- 协议森林10 魔鬼细节 (TCP滑窗管理)