HDU2028 Lowest Common Multiple Plus【stein算法】【水题】
来源:互联网 发布:五十知天命 英文 编辑:程序博客网 时间:2024/05/17 02:27
Lowest Common Multiple Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 36800 Accepted Submission(s): 15116
Problem Description
求n个数的最小公倍数。
Input
输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
Output
为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。
Sample Input
2 4 6
3 2 5 7
Sample Output
12
70
Author
lcy
思路:没有用欧几里得算法来求,用的是stein算法试一下。最大公约数、
最小公倍数的欧几里得算法和stein算法参考博文:
http://blog.csdn.net/lianai911/article/details/42003903
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;int GCD(int a,int b){ if(a == 0) return b; if(b == 0) return a; if(~a & 1) { if(b & 1) return GCD(a>>1, b); else return GCD(a>>1, b>>1)<<1; } if(~b & 1) return GCD(a, b>>1); if(a > b) return GCD((a-b)>>1, b); return GCD((b-a)>>1,a);}int LCM(int a,int b){ return a/GCD(a,b)*b;}int main(){ int N,d; while(cin >> N) { int ans = 1; for(int i = 1; i <= N; ++i) { cin >> d; ans = LCM(ans,d); } cout << ans << endl; } return 0;}
0 0
- HDU2028 Lowest Common Multiple Plus【stein算法】【水题】
- HDU2028:Lowest Common Multiple Plus
- hdu2028 Lowest Common Multiple Plus
- HDU2028 Lowest Common Multiple Plus
- HDU2028 Lowest Common Multiple Plus
- Lowest Common Multiple Plus HDU2028
- HDU2028 Lowest Common Multiple Plus
- hdu2028 Lowest Common Multiple Plus
- HDU2028 Lowest Common Multiple Plus
- Lowest Common Multiple Plus HDU2028
- Lowest Common Multiple Plus HDU2028
- hdu2028 Lowest Common Multiple Plus
- HDU2028:Lowest Common Multiple Plus
- HDU 2028 Lowest Common Multiple Plus (Stein算法 求最大公约数)
- 最大公约数最小公倍数 (例:HDU2028 Lowest Common Multiple Plus)
- hdu2028 Lowest Common Multiple Plus(C语言)
- Lowest Common Multiple Plus
- Lowest Common Multiple Plus
- 无奈人心渐开明 贪嗔痴恨爱恶欲
- linux下github的搭建使用
- Python练手之6种经典排序算法
- JUnit4---实践一:运行指定类的某些测试方法
- hdu 1021 斐波那契2,找规律
- HDU2028 Lowest Common Multiple Plus【stein算法】【水题】
- 类似spring的AOP框架,动态获得代理类或目标类
- Git 分支创建与合并
- 使用Vitamio打造自己的Android万能播放器
- onethink 中在后台创建模型的时候 在字段里面添加的函数
- UVA 340-Master-Mind Hints(STL-map)
- ffmpeg scenecut
- storm-kafka 学习
- 如何使用iCat