杭电 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 ...
随机推荐
- STL总结 (C++)
一.一般介绍 STL(Standard Template Library),即标准模板库,是一个具有工业强度的,高效的C++程序库.它被容纳于C++标准程序库(C++ Standard Library ...
- iOS开发之使用 infer静态代码扫描工具
infer是Facebook 的 Infer 是一个静态分析工具.可以分析 Objective-C, Java 或者 C 代码,报告潜在的问题. 任何人都可以使用 infer 检测应用,可以将严重的 ...
- mac 电脑安装express、npm…… 报 ‘Missing write access to /usr/local/lib/node_modules’错误解决办法
mac电脑安装express框架.npm…… 报 Missing write access to /usr/local/lib/node_modules 错误 终端输入sudo chown -R $U ...
- 粪发涂墙-redis1
redis 核心就是 如果我的数据全都在内存里,我单线程的去操作 就是效率最高的,为什么呢,因为多线程的本质就是 CPU 模拟出来多个线程的情况,这种模拟出来的情况就有一个代价,就是上下文的切换, 对 ...
- 自编C++游戏
背景 周末无聊,于是编了一个类似于cmd的小玩意. 可是越想越不对劲,所以把它改成了一个小游戏. 信息 语言:DEV_C++ 源代码已公布!! 打败GG 版本:1.0(正式版) 版本:1.5(番外) ...
- spring boot 配置logback日志之jdbcTemplate打印sql语句配置
配置jdbcTemplate打印sql 用mybaties打印语句很好配置,后来用了JdbcTemplate就不知道怎么打印了,其实JdbcTemplate执行sql语句的过程会做打印sql语句的操作 ...
- 吴裕雄 PYTHON 神经网络——TENSORFLOW 单隐藏层自编码器设计处理MNIST手写数字数据集并使用TensorBord描绘神经网络数据
import os import numpy as np import tensorflow as tf import matplotlib.pyplot as plt from tensorflow ...
- Go语言基础之runtime包
文章引用自 Golang中runtime的使用 runtime调度器是非常有用的东西,关于runtime包几个方法: Gosched:让当前线程让出cpu以让其他线程运行,它不会挂起当前线程,因此当前 ...
- 用for循环创建对象
以下代码Demo: public class TestDemo { public static void main(String[] args) { //以创建5个student为例 int coun ...
- python时间模块time,datetime
时间模块time.datetime 模块(module)是 Python 中非常重要的东西,你可以把它理解为 Python 的扩展工具.换言之,Python 默认情况下提供了一些可用的东西,但是这些默 ...