题目链接:http://ac.jobdu.com/problem.php?pid=1439

详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

参考代码:

//
// 1439 Least Common Multiple.cpp
// Jobdu
//
// Created by PengFei_Zheng on 10/04/2017.
// Copyright © 2017 PengFei_Zheng. All rights reserved.
// #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cmath> using namespace std;
//to avoid overflow thus use long long to store data
long long gcd(long long a, long long b){
return b== ? a : gcd(b,a%b);
} long long lcm(long long a, long long b){
return (a/gcd(a,b))*b;// not a*b/gcd(a,b) beacuse it may cause overflow
} int main(){
int kase;
scanf("%d",&kase);//kase number
while(kase--){//a small tips
int m;
scanf("%d",&m);
long long ans;
scanf("%lld",&ans);// input the first number
for(int i = ; i < m ; i++){
long long tmp;//to store the next number
scanf("%lld",&tmp);
ans = lcm(ans,tmp);//calculate each two adjacent elements's lcm
}
printf("%lld\n",ans);//print the answer
}
return ;
}

题目1439:Least Common Multiple(求m个正数的最小公倍数lcm)的更多相关文章

  1. HDU - 1019-Least Common Multiple(求最小公倍数(gcd))

    The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...

  2. HDU 4913 Least common multiple

    题目:Least common multiple 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4913 题意:有一个集合s,包含x1,x2,...,xn, ...

  3. hdoj-2028-Lowest common multiple plus

    题目:Lowest common multiple plus 代码: #include<stdio.h> int common(int a,int b)//计算最大公约数 { int c= ...

  4. 【九度OJ】题目1439:Least Common Multiple 解题报告

    [九度OJ]题目1439:Least Common Multiple 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1439 ...

  5. 九度OJ 1056--最大公约数 1439--Least Common Multiple 【辗转相除法】

    题目地址:http://ac.jobdu.com/problem.php?pid=1056 题目描述: 输入两个正整数,求其最大公约数. 输入: 测试数据有多组,每组输入两个正整数. 输出: 对于每组 ...

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

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

  7. HDU 3092 Least common multiple 01背包

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS ...

  8. 杭电1019Least Common Multiple

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=1019 题目: Problem Description The least common multiple ...

  9. ACM学习历程—HDU 3092 Least common multiple(数论 && 动态规划 && 大数)

    Description Partychen like to do mathematical problems. One day, when he was doing on a least common ...

随机推荐

  1. Mac下配置Oracle数据库客户端远程连接数据库服务器

    下载mac数据库客户端: 地址:http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html 下载这俩个:(来源:http:// ...

  2. Css 去除浮动

    清除浮动的方法 清除浮动方法大致有两类,一类是clear:both | left | right ,另一类则是创建BFC,细分又可以分为多种. 通过在浮动元素末尾添加一个空的标签例如并设置样式为cle ...

  3. jQuery form的load函数与el表达式赋值的冲突问题

    问题: 在使用el表达式给表单中的项赋初始值的时候,总是失败,物流公司没有自动选中,物流单号也没有显示值. <form id="form" method="post ...

  4. centos 中文乱码解决途径

    在使用CentOS系统时,安装的时候可能你会遇到英文的CentOS系统,在这中情况下安装CentOS系统时是默认安装(即英文).安装完毕后,出现的各种中文乱码.那么,我们如何解决这种问题呢. 一.Ce ...

  5. 输入控件tagsinput

    ​摘要: ​tagsinput是一款基于jQuery的插件.具有组织输入内容.校验.backspace删除等功能.当你在输入框输入结束按下enter键,tagsinput会将你输入的内容用标签封装,每 ...

  6. Simply Syntax(思维)

    Simply Syntax Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5551   Accepted: 2481 Des ...

  7. UpLoader------实现上传大文件

    代码: <div id="selectFile">选择文件1</div> <script> var da = newGuid(); var kk ...

  8. PHP从数组中找到指定元素的位置

    群里有人问,有个数组五个元素 分为1到5  现在要求 循环找出3元素的索引,怎么做性能才是最高. 我不知道哪个性能最高,但是我想提出可以用多种方式进行查找,然后进行比较选择. 我想,最简单最基础的 应 ...

  9. win10进入到安全模式的三种方法

    这里介绍三种方法: 如果能够进入到系统 点击开始--设置--更新和安全--恢复,右侧点击高级启动中的立即重启 能够进入到登陆界面 进入到登录屏幕后,在按住 Shift 键的同时依次选择“电源” > ...

  10. CPU特性漏洞测试(Meltdown and Spectre)

    2018年1月4日,国外安全研究人员披露了名为"Meltdown"和"Spectre"两组CPU特性漏洞,该漏洞波及到近20年的Intel, AMD, Qual ...