HDU 1019 (多个数的最小公倍数)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1019
Least Common Multiple
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 61592 Accepted Submission(s): 23486
3 5 7 15
6 4 10296 936 1287 792 1
10296
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int gcd(int a,int b)
{
if (b==)
return a;
return gcd(b, a%b);
}
int main()
{
//公式:a,b的最小公倍数等于a,b的乘积除以a,b的最大公约数
//直接暴力即可
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int a=,cnt=;
int x;
for(int i=;i<n;i++)
{
scanf("%d",&x);
cnt=a/gcd(a,x)*x;//先除后乘,避免溢出
a=cnt;
}
printf("%d\n",a);
}
return ;
}
HDU 1019 (多个数的最小公倍数)的更多相关文章
- hdu 1019 n个数的最小公倍数
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...
- hdu 1788(多个数的最小公倍数)
Chinese remainder theorem again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- 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 ...
- Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】
Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...
- n个数的最小公倍数
Description 求n个数的最小公倍数. Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数. Output 为每组测试数据输出它们的最小公倍数,每个测 ...
- HDOJ-ACM1019(JAVA) 多个数的最小公倍数
题意:求多个数的最小公倍数 很简单,但是我一开始的做法,估计会让结果越界(超过int的最大值) import java.util.*; import java.io.*; public class M ...
- ACM hdu 1019 Least Common Multiple
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- HDU_2028——求多个数的最小公倍数
Problem Description 求n个数的最小公倍数. Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数. Output 为每组测试数据输出它们的最 ...
- HDU 1019 Least Common Multiple GCD
解题报告:求多个数的最小公倍数,其实还是一样,只需要一个一个求就行了,先将答案初始化为1,然后让这个数依次跟其他的每个数进行求最小公倍数,最后求出来的就是所有的数的最小公倍数.也就是多次GCD. #i ...
随机推荐
- Google安装postman插件
1.保证网上商店可用 http://jingyan.baidu.com/article/48a42057ea53a1a9242504c1.html
- js如何判断字符串里面是否含有某个字符串
方法一: indexOf() (推荐) var str = "123"; console.log(str.indexOf("3") != -1 ); // tr ...
- es6 import笔记
export输出: // profile.js var firstName = 'Michael'; var lastName = 'Jackson'; var year = 1958; export ...
- 第1章:程序设计和C语言(C语言入门)
一.程序和程序语言 1,程序的概念:完成某项事物所预设的活动方式. 2,程序设计:人们描述计算机要做的工作. 二 .程序设计语言及其发展 1.机器语言,2汇编语言,3高级语言{a)编译,b)解释}: ...
- Django Cookie于Session
一.Cookie与Session由来 因为Http协议的特性,每一次来自用户浏览器的请求都是无状态且独立的,通俗地说,就是无法保存用户状态,后台服务器根本就不知道当前请求和以前及以后请求是否来自同一用 ...
- C# CRC16算法实现【转】
/// <summary> /// CRC校验 /// </summary> public class CRC { #region CRC16 public static by ...
- apk下载安装,存储的位置,路径
PackageInstaller 原理简述 应用安装是智能机的主要特点,即用户可以把各种应用(如游戏等)安装到手机上,并可以对其进行卸载等管理操作.APK是Android Package的缩写,即An ...
- 遍历查询结果集,update数据
select NULL mykey, * into #mytemp from dbo.DIM_DISTRIBUTOR declare @i int begin ) print @i )) where ...
- Linux入门-1 常用命令
写在前面 当年初学Linux的时候,在网上找到nash_su大神的一套视频,讲的特别好,基础部分看了好几遍,很多知识点让我受益至今. 十分庆幸当年的选择,也十分感谢nash_su大神,祝你事事顺心,每 ...
- 105 + 106. Construct Binary Tree from Preorder and Inorder Traversal (building trees)
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that ...