hud 1019最小公倍数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1019
思路:头两个数先求,再用所求的数与后面的一个数求,依次类推
#include<stdlib.h>
#include<time.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string.h>
using namespace std; int n,m;
int arr[]; int gcd(int a,int b)
{
if(b)
return gcd(b,a%b);
else
return a;
} int lcm(int a,int b)
{
return a/gcd(a,b)*b; //此处不能用a*b/gcd(a,b)数据会溢出
} int main()
{
while(scanf("%d",&n)!=EOF)
{
while(n--)
{
scanf("%d",&m);
int t;
scanf("%d",&t);
for(int i=;i<=m-;i++)
{
scanf("%d",&arr[i]);
t=lcm(t,arr[i]);
}
printf("%d\n",t); }
}
return ;
}
hud 1019最小公倍数的更多相关文章
- (杭电1019 最小公倍数) Least Common Multiple
Least Common Multiple Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1019 (多个数的最小公倍数)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (J ...
- HDOJ 1019 Least Common Multiple(最小公倍数问题)
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- hdu 1019 n个数的最小公倍数
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...
- HDU 1019(求最小公倍数 **)
题意是求一组数的最小公倍数,不用存,每次输入即刻处理即可. 补充一点:两个自然数的最大公约数与它们的最小公倍数的乘积等于这两个数的乘积. 代码如下: #include <bits/stdc++. ...
- 杭电1019 Least Common Multiple【求最小公倍数】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1019 解题思路:lcm(a,b)=a*b/gcd(a,b) 反思:最开始提交的时候WA,以为是溢出了, ...
- hdu 1788 Chinese remainder theorem again(最小公倍数)
Problem Description 我知道部分同学最近在看中国剩余定理,就这个定理本身,还是比较简单的: 假设m1,m2,-,mk两两互素,则下面同余方程组: x≡a1(mod m1) x≡a2( ...
- 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 ...
随机推荐
- .apache2 设置多个虚拟域名
<VirtualHost 127.0.0.2:80> ServerName www.xylilun.cn DocumentRoot E:/www/ylll <Directory E: ...
- PYTHON 自动化学习之路
一.用户交互小程序 username = 'gyc' password = 'gyc' u = input("what is you name?:") p = input(&quo ...
- 对C++虚函数、虚函数表的简单理解
一.虚函数的作用 以一个通用的图形类来了解虚函数的定义,代码如下: #include "stdafx.h" #include <iostream> using name ...
- Android列表控件ListView详解
ListView绝对可以称得上是Android中最常用的控件之一,几乎所有应用程序都会用到它. 由于手机屏幕空间都比较有限,能够一次性在屏幕上显示的内容并不多,当我们的程序中有大量的数据需要展示的时候 ...
- 国外开源的PACS服务器
国外开源的PACS服务器 罗朝辉(http://www.cnblogs.com/kesalin/) 本文遵循"署名-非商业用途-保持一致"创作公用协议 名称:Dcm4che评级:★ ...
- CISCO系列交换机如何清空配置
今天刚好要还原一台CISCO配置的命令,这个毕竟属于我的专业小编就献丑一回,望大家见谅! 工具/原料 CISCO系列交换 方法/步骤 1 首先备份之前的配置信息 copy flash:conf ...
- Android架构:用消息机制获取网络数据
网络请求,不管是什么协议,是长连接还是短连接,总是一个异步的请求,过程包括:加请求参数->发起请求->接收响应->解析数据->获得业务数据. 最挫的做法是,业务代码包揽所有这些 ...
- python list 的+、+=和extend操作
据说后者在list很大的时候性能稍好. 于是测试了一把: import time def time_cost(func): def _time_cost(*args,**kw): t1=time.ti ...
- 5. apktool 给XX手机卫士加广告页
一. 编写广告页 写一个广告页面,并调用其他页面的demo (1) 设计界面如下 (2) 编写代码如下 public class SplashActivity extends Activity { ...
- MySql 导出excel
select * into outfile './bestlovesky.xls' from bestlovesky where 1 order by id desc limit 0, 50;