Hdoj 1019 Least Common Multiple

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

    2
    3 5 7 15
    6 4 10296 936 1287 792 1 

Sample Output

    105
    10296
题意:求所有数的最小公倍数,不断去掉两个数,把他们的最下公倍数作为下一个数,再取,知道取完,就得到了答案。 
///@zhangxiaoyu
///2015/8/13

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;

int gcd(int a,int b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}

int main()
{
  int tt;
  int m,a,b;
  while(scanf("%d",&tt)!=EOF)
  {
      for(int i=0;i<tt;i++)
      {
          scanf("%d",&m);
          a=1;
          for(int j=0;j<m;j++)
          {
              scanf("%d",&b);
              a=a/gcd(a,b)*b;
          }
          printf("%d\n",a);
      }
  }
  return 0;
}
全部评论

相关推荐

大方的大熊猫准备进厂:1.教育背景:你希望从事什么专业的工作你的主修课就是什么;成绩优秀是你应该做的,没什么可描述的,成绩不优秀也许人家在大学忙着创业呢?(成绩优秀不一定是好事,只能说明多元化的大学你上成了高中,没有真正上明白大学,反而体现了你死板,不爱社交,没有别的突出能力) 2.实践经历:你想表达的意思没有说清楚。你是说你会个性化服务,还是你有实习经历。如果没有带来,经济收益,表彰,更好的发展前景,那你还不如说说提升了自己哪些技能。你说有人给你送锦旗我都能明白你优秀,但是你说你会xxxx,你说这话谁信,证据呢。 3.入伍经历:你描述的就是你的工作职责或者你应该做的,并没有体现出来你把这个事情做好了,而且入伍经历并不能证明你能干好你要应聘的工作,不如只写经历其余所有内容都不写。 4.荣誉技能:重点突出一下,但不要过多描述,这些荣誉的含金量懂得都懂。 重点:你要应聘什么工作(具体岗位,实习生不具体),你的期望薪资
点赞 评论 收藏
分享
待现的未见之事:起码第一句要把自己的优势说出来吧。比如什么xx本27届学生,随时到岗....
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务