您的位置:首页 > 其它

zzulioj 1806: n个数的最小公倍数 (GCD)

2015-12-09 13:49 260 查看

1806: n个数的最小公倍数

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 188  Solved: 100

SubmitStatusWeb
Board

Description

给定n个数字,求这n个数字的最小公倍数。

Input

输入分两行,第一行是一个n,代表有n个数字,接着第二行输入n个数字,数字均在int范围内

Output

输出这n个数字的最小公倍数,保证结果在int范围内

Sample Input

3
1 2 3

Sample Output

6
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define INF 0x3f3f3f3f
#define N 1010
#define ll long long
using namespace std;
int a
;
ll gcd(ll x,ll y)
{
ll t;
if(x<y){t=x;x=y;y=t;}
return y?gcd(y,x%y):x;
}
int main()
{
int n,i,j;
ll sum;
while(scanf("%d",&n)!=EOF)
{
sum=1;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum=sum*a[i]/gcd(sum,a[i]);
}
printf("%lld\n",sum);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: