杭电 2028 ( Lowest Common Multiple Plus )
链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2028
题目要求:就是求最大公倍数,我百度了一下,最好实现的算法就是:
例如,求[18,20],即得[18,20]=18×20÷(18,20)=18×20÷2=180。求几个自然数的最小公倍数,可以先求出其中两个数的最小公倍数,再求这个最小公倍数与第三个数的最小公倍数,依次求下去,直到最后一个为止。最后所得的那个最小公倍数,就是所求的几个数的最小公倍数。
#include <iostream>
#include<math.h>
#include <iomanip>
#include<cstdio>
#include<string>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<stdlib.h>
#include<iterator>
using namespace std; int gcd(int a,int b)
{
int big=a;
int smal=b;
int ck;
if(big<smal)
{
ck=a;
a=b;
b=a;
}
int temp;
while(smal>)
{
temp=big%smal;
big=smal;
smal=temp;
}
return big;
} unsigned int gys(unsigned int a,unsigned int b)
{
unsigned int kk;
unsigned int ak=a;
unsigned int bk=b;
kk=ak*bk/gcd(ak,bk);
return kk;
} int main()
{ int n;
while(cin>>n)
{
unsigned int *p;
p=new unsigned int[n]; for(int i=;i<n;i++)
{
cin>>p[i];
} int unsigned max_gys=p[]; for(int j=;j<n-;j++)
{
max_gys=gys(max_gys,p[j+]);
}
cout<<max_gys<<endl; delete []p;
} return ;
}
杭电 2028 ( Lowest Common Multiple Plus )的更多相关文章
- hdu 2028 Lowest Common Multiple Plus(最小公倍数)
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- HDU 2028 Lowest Common Multiple Plus
http://acm.hdu.edu.cn/showproblem.php?pid=2028 Problem Description 求n个数的最小公倍数. Input 输入包含多个测试实例,每个 ...
- #2028 Lowest Common Multiple Plus
http://acm.hdu.edu.cn/showproblem.php?pid=2028 应该是比较简单的一道题啊...求输入的数的最小公倍数. 先用百度来的(老师教的已经不知道跑哪去了)辗转相除 ...
- 杭电1019 Least Common Multiple【求最小公倍数】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1019 解题思路:lcm(a,b)=a*b/gcd(a,b) 反思:最开始提交的时候WA,以为是溢出了, ...
- 最大公约数最小公倍数 (例:HDU2028 Lowest Common Multiple Plus)
也称欧几里得算法 原理: gcd(a,b)=gcd(b,a mod b) 边界条件为 gcd(a,0)=a; 其中mod 为求余 故辗转相除法可简单的表示为: int gcd(int a, int b ...
- Lowest Common Multiple Plus
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 2028 ACM Lowest Common Multiple Plus
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2028 思路:最一想到的就是暴力求解,从1开始一直到最后的答案,一直来除以给出的数列的数,直到余数为0:当然 ...
- 【HDU 2028】Lowest Common Multiple Plus
Problem Description 求n个数的最小公倍数. Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数. Output 为每组测试数据输出它们的最小公倍数 ...
- HDU2028 Lowest Common Multiple Plus
解题思路:最近很忙,有点乱,感觉对不起自己的中国好队友. 好好调整,一切都不是问题,Just do it ! 代码: #include<cstdio> int gcd(int a, i ...
随机推荐
- 如何用 Python 实现超级玛丽的人物行走和碰撞检测?
功能介绍 人物行走 人物的行走速度这边分成水平方向(X轴)和竖直方向(Y轴),水平方向的速度要考虑加速度和摩擦力,竖直方向的速度要考虑重力加速度. 水平方向:设定X轴向右走的速度为大于0,向左走的 ...
- dfs序与求子树子节点(染了色)的个数
https://blog.csdn.net/hpu2022/article/details/81910490 https://blog.csdn.net/qq_39670434/article/det ...
- linux使用wget下载https开头url的文件
可以使用命令 : 比如我们可以修改成: wget --no-check-certificate https://我们下载文件路径 来自: http://www.laozuo.org/3648.html
- [Bug合集] java.lang.IllegalStateException: Could not find method onClickcrea(View) in a parent
出现场景: 在一个Button中定义了onclick属性,值为startChat. 在Activity中定义一个方法. public void startChat(View view){} 运行时,点 ...
- 原生js登录创建cookie
原生js创建cookie,功能:点击登录按钮时,将用户名.密码存为cookie:页面再次加载时,自动读取cookie中的用户名.密码. <html><head><titl ...
- 【Struts 分派Action】DispatchAction
LoginAction package k.action; import k.form.UserForm; import org.apache.struts.action.ActionForm; im ...
- MySQL的多表查询学习笔记
一.案例准备 create table dept( id int primary key auto_increment, name ) ); insert into dept values(null, ...
- linux chrome rpm chrome浏览器下载(ver 63-70)
我的github chrome下载地址:https://github.com/chen1932390299/python 国内开源的资源 chrome下载centos 的:https://www.ch ...
- No space left on device(转载)
本文转自 http://blog.163.com/ly_89/blog/static/186902299201191233058625/ =====================概述======== ...
- Cosmetic Bottles - Cosmetic Packaging: What Are The Characteristics Of Trends?
There are certain differences in products, of which cosmetics are the most obvious. In addition to t ...