杭电1019Least Common Multiple
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1019
题目:
3 5 7 15
6 4 10296 936 1287 792 1
10296
long gcd(long a,long b)
{ long r=;
while (r>)
{
r=a%b;
a=b;
b=r;
}
return a;}
lcm(a,b)=a*b/gcd(a,b);
代码:
long lcm(long a,long b)
{
return a/gcd(a,b)*b;
}
ac代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <vector> #define PI acos((double)-1)
#define E exp(double(1))
using namespace std; long gcd(long a,long b)
{ long r=;
while (r>)
{
r=a%b;
a=b;
b=r;
}
return a;
// if(b)
// while( (a%=b) && (b %= a));
// return a+b;
} long lcm(long a,long b)
{
return a/gcd(a,b)*b;
}
int main (void)
{
int t,n;
cin>>t;
while(t--)
{
long temp,m;
cin>>n;
scanf("%ld",&temp);
for(int i = ;i<n;i++)
{
scanf("%ld",&m);
temp = lcm(temp,m);
}
cout<<temp<<endl; }
return ;
}
杭电1019Least Common Multiple的更多相关文章
- 杭电1019-Least Common Multiple
#include<stdio.h>int gcd(int a,int b);int main(){ int n,m,a,b,i,sum;//sum是最小公倍数 scanf(&q ...
- HDU——1019Least Common Multiple(多个数的最小公倍数)
Least Common Multiple Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- HDU - 1019-Least Common Multiple(求最小公倍数(gcd))
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...
- 杭电 1159 Common Subsequence
Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...
- 杭电1159 Common Subsequence【最长公共子序列】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 解题思路:任意先给出两个字符串 abcfbc abfcab,用dp[i][j]来记录当前最长的子 ...
- (杭电1019 最小公倍数) Least Common Multiple
Least Common Multiple Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 杭电dp题集,附链接还有解题报告!!!!!
Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱 最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f ...
- 2018 Multi-University Training Contest 1 杭电多校第一场
抱着可能杭电的多校1比牛客的多校1更恐怖的想法 看到三道签到题 幸福的都快哭出来了好吗 1001 Maximum Multiple(hdoj 6298) 链接:http://acm.hdu.edu. ...
随机推荐
- 网易AI工程师面试常见知识
- Angular2 组件与模板 -- 输入和输出属性
Input and Output properties 输入属性是一个带有@Input 装饰器的可设置属性,当它通过属性绑定的形式被绑定时,值会"流入"到这个属性. 输出属性是一个 ...
- Java知识点梳理——装箱和拆箱
1.前言:Java是典型的面向对象编程语言,但其中有8种基本数据类型不支持面向对象编程,基本数据类型不具备对象的特性,没有属性和方法:Java为此8种基本数据类型设计了对应的类(包装类),使之相互转换 ...
- 重写equals()方法也要重写hashcode()方法
如果我们对equals方法进行了重写,建议一定要对hashCode方法重写,以保证相同的对象返回相同的hash值,不同的对象返回不同的hash值.
- 83、android的消息处理机制(图+源码分析)——Looper,Handler,Message
转载:http://www.cnblogs.com/codingmyworld/archive/2011/09/12/2174255.html https://my.oschina.net/u/139 ...
- 盘点:七大.NET著名开源项目
尽管过了相当长的时间,花费了不少资源,微软和.NET社区还是在最近几年加入到了开源运动的阵营中来了,这令人相当惊讶,因为两大阵营一直都是经常对立的.然而,事实是依靠开源,微软社区中的开源开发工具日益发 ...
- std::ostringstream
ostringstream是C++的一个字符集操作模板类,定义在sstream.h头文件中.ostringstream类通常用于执行C风格的串流的输出操作,格式化字符串,避免申请大量的缓冲区,替代sp ...
- nginx的allow和deny配置
转自:http://www.ttlsa.com/linux/nginx-modules-ngx_http_access_module/ 单看nginx模块名ngx_http_access_module ...
- CSS 垂直外边距合并:规范、延伸、原理、解决办法
<CSS 权威指南>第七章基本视觉格式化.p192,提到了 垂直外边距合并 的情况,解释总体算清晰,但是感觉不全且没有归纳成一条一条的,参考 CSS框模型中外边距(margin)折叠图文详 ...
- quartz启动Quartz : org.quartz.SchedulerConfigException: Thread count must be > 0
检查quartz.properties数据源配置是否正常