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. Reveal for mac延长30天试用的简单方法

    在iOS逆向过程中经常使用Reveal来远程查看iOS平台应用的UI布局,但Reveal有30天使用限制,经常隔一段时间想使用的时候发现已经过期了,如图: 此时在OS X中打开命令行终端,输入以下命令 ...

  2. 前端面试题 之 JavaScript

    昨天我们一起分享了关于html和css的面试题<前端面试题之Html和CSS>,今天我们来分享关于javascript有关的面试题.我面试的时候最害怕面试官问我js了,因为我真心不擅长这个 ...

  3. 关于HTML5、Jquery、Phonegap跨域问题的研究

    我的问题: 近期研究Phonegap的相关技术,遇到了服务资源访问的跨域.经过尝试使用服务器端的代理,Phonegap打包后不能够访问到相应资源.在搜索引擎的帮助下,找到了Jquery的jsonp的方 ...

  4. Struts2 Result 类型和对应的用法详解 2

  5. OpenCV 学习

    #include <opencv2\opencv.hpp> #include <iostream> #include <opencv2\highgui\highgui.h ...

  6. Java如何解决脆弱基类(基类被冻结)问题

    概述  大多数好的设计者象躲避瘟疫一样来避免使用实现继承(extends 关系).实际上80%的代码应该完全用interfaces写,而不是通过extends.“JAVA设计模式”一书详细阐述了怎样用 ...

  7. ES6模块加载

    两种加载方式 加载方式 规范 命令 特点 运行时加载 CommonJS/AMD require 社区方案,提供了服务器/浏览器的模块加载方案 非语言层面的标准 只能在运行时确定模块的依赖关系及输入/输 ...

  8. [小菜随笔]关于monkey报错日志分析

    今天小菜在一个测试群内看到群友发出一个monkey的报错信息,其实是一个很简单的报错 个人觉得monkey虽然操作起来比较简易,但其实查看日志分析日志也是很重要的环节,如果对错误分析不够详细,就容易误 ...

  9. CentOS 7 Hadoop安装配置

    前言:我使用了两台计算机进行集群的配置,如果是单机的话可能会出现部分问题.首先设置两台计算机的主机名 root 权限打开/etc/host文件 再设置hostname,root权限打开/etc/hos ...

  10. Ubuntu下mysql-server的安装

    (1)更新 #apt-get update (2)安装 #apt-get install mysql-server 出现窗口设置"root"用户的密码为"456456&q ...