题目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 ...
随机推荐
- idea出现插件突然失灵解决方案
File -> Settings -> Plgins 把失效的插件重新去掉打钩并重新打钩即可
- iOS 模拟器的“调试-位置”总是变成无的问题
选择项目的“Edit Scheme...” 并且选择“Options”选项卡,更改你喜欢的默认地理位置 你也可以编辑一个gpx文件永久保存坐标,或者在线生成(传送门). 转自:iOS Simulato ...
- 【转】Spring Boot干货系列:常用属性汇总
转自Spring Boot干货系列:常用属性汇总 附录A.常用应用程序属性 摘自:http://docs.spring.io/spring-boot/docs/current/reference/ht ...
- Oracle中已知字段名查询所在的表名
select table_name from user_tab_columns where column_name = '字段名'; 这是网上查到的,地址如下:http://blog.163.com/ ...
- Fedora更改密码
开机进入单用户模式 按e --->进入编辑界面之后,在“rhgb quiet”字符前面,输入“single”加空格,回车-->返回上一步中启动命令行菜单. 按 b ---> pas ...
- 在Unity3d中调用外部程序及批处理文件
如果调用外部普通应用程序, 比如notepad.exe 这样调用 static public bool ExecuteProgram(string exeFilename, string workDi ...
- mysql中查看视图的元数据?
需求描述: 查看视图的元数据的方法. 操作过程: 1.通过查看information_schema数据库下的views表来查看视图的定义语句 mysql> select definer,view ...
- 分享一个有趣的代码,调用电脑中的api语音
在文本文件中输入如下代码: set objTTS = CreateObject("sapi.spvoice") objTTS.speak("为啥我对象这么闹呢?" ...
- Jquery/js submit()无法提交问题
有朋友可能会直接利用js或jquery来提交数据而不是使用表单直接提交了,小编来给大家介绍小编碰到的一个问题就是 submit()无法提交,下面我们来看解决办法与原因分析. jquery无法提交 代 ...
- ios开发之--复制到剪切板
仅做记录: UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = @"你好&quo ...