HDOJ Lowest Common Multiple Plus 2028

来源:互联网 发布:广告宣传语音制作软件 编辑:程序博客网 时间:2024/05/16 14:13

Lowest Common Multiple Plus

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 39817    Accepted Submission(s): 16482


Problem Description
求n个数的最小公倍数。
 

Input
输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
 

Output
为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。
 

Sample Input
2 4 63 2 5 7
 

Sample Output
1270
 

Author
lcy
 

Source
C语言程序设计练习(五)
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  2021 2899 2199 1215 2048 
 


 

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;__int64 gcd(__int64 a,__int64 b){if(b==0)return a;return gcd(b,a%b);}__int64 lcm(__int64 a,__int64 b){__int64 num=a*b;return num/gcd(a,b);}int main(){int n;while(scanf("%d",&n)!=EOF){__int64 s,x;__int64 res;scanf("%I64d",&s);res=s;for(int i=1;i<n;i++){scanf("%I64d",&x);res=lcm(x,res);}printf("%I64d\n",res);}return 0;}


 

0 0