杭电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. ...
随机推荐
- MFC 单选按钮Radio使用注意
使用MFC Radio时遇到问题:数据交换时出现断言崩溃框 定位于: 解决方法: 1.按CTRL+D,保证同一组内的radio的tab序号是连续的: 2.同一组内,设置 radio1的属性: gro ...
- C++之运行时类型识别RTTI
C++ Code 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 ...
- eclipse中打开含有汉字的properties文件显示乱码
http://blog.csdn.net/wangjun5159/article/details/46965831
- ios 从URL中截取所包含的参数,并且以字典的形式返回和参数字典转URL
//字典转链接(参数) - (NSString *)keyValueStringWithDict:(NSDictionary *)dict { if (dict == nil) { return ni ...
- springmvc 发送PUT 和 DELETE 请求
一: 发送 DELETE 或者 PUT 请求: 1.在表单中加入一个隐藏的参数: _method , 值是 DELETE (或者PUT) <form action="springmv ...
- iOS开发之--搭建本地的SVN服务器
近期入职的新公司,后台没有分配svn账号,需要在本地搭建一个服务器,方便和代码,看了看网上的教程,一直有这样那样的问题, 其中最主要的问题还是路径拼接的问题,最后终于解决了,特在此分享下,如果大家有更 ...
- ImageLoader must be init with configuration before using
遇到上面的问题是没有全局初使化ImageLoader,我是在Application中配置了ImageLoaderConfiguration 解决的,当然还有官方的写法 public class MyA ...
- vue的递归组件以及三级菜单的制作
js里面有递归算法,同时,我们也可以利用props来实现vue模板的递归调用,但是前提是组件拥有 name 属性 父组件:slotDemo.vue: <template> <div& ...
- jquery做简单特效
1.点击触发消失效果 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> &l ...
- hammer.js移动端手势库
hammer.js 是一个多点触摸手势库,能够为网页加入Tap.Double Tap.Swipe.Hold.Pinch.Drag等多点触摸事件,免去自己监听底层touchstart.touchmove ...