题目1439:Least Common Multiple(求m个正数的最小公倍数lcm)
题目链接: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)的更多相关文章
- HDU - 1019-Least Common Multiple(求最小公倍数(gcd))
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...
- HDU 4913 Least common multiple
题目:Least common multiple 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4913 题意:有一个集合s,包含x1,x2,...,xn, ...
- hdoj-2028-Lowest common multiple plus
题目:Lowest common multiple plus 代码: #include<stdio.h> int common(int a,int b)//计算最大公约数 { int c= ...
- 【九度OJ】题目1439:Least Common Multiple 解题报告
[九度OJ]题目1439:Least Common Multiple 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1439 ...
- 九度OJ 1056--最大公约数 1439--Least Common Multiple 【辗转相除法】
题目地址:http://ac.jobdu.com/problem.php?pid=1056 题目描述: 输入两个正整数,求其最大公约数. 输入: 测试数据有多组,每组输入两个正整数. 输出: 对于每组 ...
- ACM-简单题之Least Common Multiple——hdu1019
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...
- HDU 3092 Least common multiple 01背包
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS ...
- 杭电1019Least Common Multiple
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1019 题目: Problem Description The least common multiple ...
- ACM学习历程—HDU 3092 Least common multiple(数论 && 动态规划 && 大数)
Description Partychen like to do mathematical problems. One day, when he was doing on a least common ...
随机推荐
- DbHelper.ttinclude 更新,查询视图和表
<#+ public class DbHelper { #region GetDbTables public static List<DbTable> GetDbTables(str ...
- SOA及分布式
结合领域驱动设计的SOA分布式软件架构 Windows平台分布式架构实践 - 负载均衡(下) 分享一个分布式消息总线,基于.NET Socket Tcp的发布-订阅框架,附代码下载 我终于深入参与了一 ...
- bind带autocomplete时,最好是从新的tr复制
(function($) { //自动关联ItemNo $.fn.extend({ productitemlist: function(options) { return this.each(func ...
- 如何设置Jquery UI Menu 菜单为横向展示
Jquery UI Menu 默认是纵向展示的.Jquey UI Menu 设置API,http://api.jqueryui.com/menu/#option-position 修改对应的CSS可 ...
- 如何在IntelliJ IDEA中快速配置Tomcat
近来使用idea编写java代码的人越来越多,最关键的就是idea强大的代码提示功能,能极高的提升程序员的开发效率,但是毕竟各有所长,idea中tomcat的配置就没有eclipse那么轻松,这里简单 ...
- python 在windows 中文显示
今天看到mechanize,在网上找例子实验,发现只要代码里出现中文,就会报错 SyntaxError: Non-ASCII character , but no encoding declared; ...
- geoserver PostGIS的安装和使用
PostGIS是一个非常流行并且开源的具有空间分析能力的关系型数据库,它作为PostgreSQL数据库的一个插件.PostgreSQL是一个功能非常强大并且开源的关系型数据库.目前项目使用的版本为Po ...
- spring aop的配置
http://www.cnblogs.com/oumyye/p/4480196.html http://blog.csdn.net/hjm4702192/article/details/1727766 ...
- while 1要小心
之前判断一个接口的返回,一定约定好了是返回retcode 1或者retcode 0,就用的这个判断,但是接口挂了的时候,一直返回未登录,找了很长时间为什么cpu一直消耗那么高. 使用wihle 1时候 ...
- iOS中js与objective-c的交互(转)
因为在iOS中没有WebKit.Framework这个库的,所以也就没有 windowScriptObject对象方法了.要是有这个的方法的话 就方便多了,(ps:MacOS中有貌似) 现在我们利用其 ...