Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

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
 
这道题就是要求多个数的最小公倍数;
思路很简单,就是每两个数求他们的最小公倍数,然后用求出的最小公倍数与下一个数
 #include<stdio.h>
int gcd(int a,int b)
{
if(b==) return a;
return gcd(b,a%b);
}
int main()
{
int t;
int n,a,b,i;
int cnt;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
cnt=a=;
for(i=;i<=n;i++)
{
scanf("%d",&b);
cnt=a/gcd(a,b)*b;
a=cnt;
}
printf("%d\n",cnt);
}
return ;
}
 

K - Least Common Multiple的更多相关文章

  1. HDOJ2028Lowest Common Multiple Plus

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  2. hdu 2028 Lowest Common Multiple Plus(最小公倍数)

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  3. HDU-1019 Least Common Multiple

    http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (Java/ ...

  4. HDOJ 1019 Least Common Multiple(最小公倍数问题)

    Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...

  5. Lowest Common Multiple Plus

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...

  6. ACM-简单题之Least Common Multiple——hdu1019

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  7. 1019 Least Common Multiple

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  8. HDU 1019 Least Common Multiple【gcd+lcm+水+多个数的lcm】

    Least Common Multiple Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  9. hdu_1019Least Common Multiple(最小公倍数)

    太简单了...题目都不想贴了 //算n个数的最小公倍数 #include<cstdio> #include<cstring> #include<algorithm> ...

随机推荐

  1. java 将数据写进文件

    /*每次只写入一行数据 只需要调用特定的方法即可.*/package com.second.File;import java.io.*;/** * Created by hasee on 2016/1 ...

  2. PHP 捕捉错误,记录到日志

    register_shutdown_function("shutdown"); define('ERR_LOG_FILE', '/dev/shm/php_log.txt'); if ...

  3. callback 转换到 promise

    最近项目迭代,从express到koa,面对callback,想偷懒,就想到了Proxy对象 new Proxy(docker,{ get : function (obj,name) { return ...

  4. android app 提示信息

    Toast.makeText(this,"You cannot have less than 1 coffee",Toast.LENGTH_SHORT).show();TextVi ...

  5. (1)WCF少废话系列之 _Hello WCF!

    本节旨在通过实例的方式让初学者对WCF有一个感性的认识,坚持由特殊到普遍再由普遍到特殊的认知规律. WCF(Windows Communication Fundation),微软分布式通信架构的集合, ...

  6. Unique Paths II

    这题在Unique Paths的基础上增加了一些obstacle的位置,应该说增加的难度不大,但是写的时候对细节的要求多了很多,比如,第一列的初始化会受到之前行的第一列的结果的制约.另外对第一行的初始 ...

  7. 百度前端技术学院2015JavaScript基础部分-BOM

    5.1 任务描述 实现以下函数 // 判断是否为IE浏览器,返回-1或者版本号 function isIE() { // your implement } // 设置cookie function s ...

  8. 也来说说C/C++里的volatile关键字

    去年年底的样子,何登成写了一篇关于C/C++ volatile关键字的深度剖析blog(C/C++ Volatile关键词深度剖析).全文深入分析了volatile关键字的三个特性.这里不想就已有内容 ...

  9. 关于mongodb的复合索引新功能

    最新在做一个项目,由于查询字段较多,且查询较频繁,所以我做了一个复合索引,将所有需要查询的字段都做到索引里,做了一个名为s_1_m_1_c_1_v_1_year_1_month_1_week_1_da ...

  10. 2014年7月份第2周51Aspx源码发布详情

      体育馆综合会员管理系统源码  2014-7-11 [VS2010]功能介绍:本系统适用于羽毛球馆,台球馆,乒乓球馆,棋牌室,篮球馆等综合体育馆,可同时使用.本系统功能非常强大,包含体育馆内餐厅,超 ...