题目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 ...
随机推荐
- 本地没问题 服务器 提示 Server Error in '/' Application
一. 先用本机的 IIS 测试,不要用 VS 内附的 Web server,並配置 <customErrors mode="Off"/>,以將真實的錯誤原因顯示出來,看 ...
- thinkphp3.2 session时间周期无效
Thinkphp3.2 session周期时间默认是无效的 方法一: 这种方法使用session非常麻烦 1.配置'SESSION_AUTO_START' =>false,2.控制器方法sess ...
- GCT之数学公式(微积分)
- php解析mpp文件中的多级任务
获取层级的project任务 参考 启动javabridge java -jar JavaBridge.jar SERVLET_LOCAL:8089 1.读取mpp文件 $file_path = & ...
- ava中有三种移位运算符
转自:http://www.cnblogs.com/hongten/p/hongten_java_yiweiyunsuangfu.html << : 左移运算符,num ...
- Go 文件操作(创建、打开、读、写)
https://blog.csdn.net/Tovids/article/details/77887946
- Eclipse------maven使用Maven build编译web项目显示" javax.servlet.http 不存在"
缺少javax.servlet包 解决方法: 引入下面代码即可 <project> <dependencies> <dependency> <groupId& ...
- SpringMVC -- 梗概--源码--贰--静态资源的访问问题
配置:<mvc:default-servlet-handler/> 1>静态资源:除了Servlet.Controller之外的资源,如:js,css,png,html等 2> ...
- lua 按拉分析与合成
-- 将数值分解成bytes_table local function decompose_byte(data) if not data then return data end local tb = ...
- 【Nodejs】npm cnpm 淘宝镜像
一.通过命令配置 1. 命令 npm config set registry https://registry.npm.taobao.org 2. 验证命令 npm config get regist ...