注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Minary_Acdream

http://f10.moe/

 
 
 

日志

 
 

[hdu]1019 Least Common Multiple  

2012-08-13 17:46:15|  分类: HDU |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
这题就是求最大公倍数。

Least Common Multiple

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


Problem Description
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105.

 

Input
Input will consist of multiple problem instances. The first line of the input will contain a single integer indicating the number of problem instances. Each instance will consist of a single line of the form m n1 n2 n3 ... nm where m is the number of integers in the set and n1 ... nm are the integers. All integers will be positive and lie within the range of a 32-bit integer.
 

Output
For each problem instance, output a single line containing the corresponding LCM. All results will lie in the range of a 32-bit integer.
 

Sample Input
3 5 7 15
6 4 10296 936 1287 792 1
 

Sample Output
105 
10296
 

Source
 

Recommend
JGShining
 



#include<iostream>
#include<cmath>
using namespace std;
int a[100010];

int HCM(int a,int b)//公约数
{
if (b == 0)
return a;
else
return HCM(b,a % b);
}

int LCM(int a,int b)//公倍数
{
return a / HCM(a,b)* b;
}

int main()
{
int N; cin>>N;
while(N--)
{
int n; cin>>n;
for(int i = 0;i < n;i ++)
{
scanf("%d",&a[i]);
}
int num = a[0];
for(int i = 1;i < n;i++)
{
num = LCM(num,a[i]);
}
cout<<num<<endl;
}
}


/*
Sample Input
2
3 5 7 15
6 4 10296 936 1287 792 1


Sample Output
105
10296
*/




  评论这张
 
阅读(198)| 评论(2)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018