Problem Description

求n个数的最小公倍数。

Input

输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。

Output

为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。

Sample Input

2 4 6

3 2 5 7

Sample Output

12

70


注意:用gcd求最小公倍数是,若两个数相乘后再除以最大公约数,可能会导致数据超限,从而wa,因此应改变一下运算的顺序

#include<stdio.h>
int gcd(int x,int y)
{
return y==0?x:gcd(y,x%y);
}
int bei(int x,int y)
{
//return x*y/gcd(x,y);**此方法计算会导致数据超限**
return (x/gcd(x,y))*y;
}
int main()
{
int n,x,y=1;
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
y=bei(x,y);
}
printf("%d\n",y);
y=1;
}
return 0;
}

HDU2028:Lowest Common Multiple Plus的更多相关文章

  1. 最大公约数最小公倍数 (例:HDU2028 Lowest Common Multiple Plus)

    也称欧几里得算法 原理: gcd(a,b)=gcd(b,a mod b) 边界条件为 gcd(a,0)=a; 其中mod 为求余 故辗转相除法可简单的表示为: int gcd(int a, int b ...

  2. hdu 2028 Lowest Common Multiple Plus(最小公倍数)

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  3. Lowest Common Multiple Plus

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...

  4. 【九度OJ】题目1439:Least Common Multiple 解题报告

    [九度OJ]题目1439:Least Common Multiple 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1439 ...

  5. leetcode:Lowest Common Ancestor of a Binary Search Tree

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  6. 题目1439:Least Common Multiple(求m个正数的最小公倍数lcm)

    题目链接:http://ac.jobdu.com/problem.php?pid=1439 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  7. LeetCode OJ:Lowest Common Ancestor of a Binary Tree(最近公共祖先)

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  8. LeetCode OJ:Lowest Common Ancestor of a Binary Search Tree(最浅的公共祖先)

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  9. ACM1019:Least Common Multiple

    Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...

随机推荐

  1. mongodb细节

    MongoDB中数值型默认为Double,可以使用NumberInt()函数及NumberLong()函数分别指定某个字段为整型和长整型.

  2. global 全局变量 nonlocal 局部变量

    # x= # def func(): # x= # # func() # print(x) # x=[] # def func(): # x.append() # x.append() # x.app ...

  3. 过滤器 拦截器 登录login实例

    当请求来的时候,首先经过拦截器/过滤器,在经过一系列拦截器/拦截器处理后,再由再根据URL找到Servlet.执行servlet中的代码. 过滤器:按照过滤的对象类型的不同,可分为按资源名过滤和按请求 ...

  4. python造数

    做性能测试时,往往需要大量的参数化数据,比如注册. from random import Random def random_str(randomlength=8): str='' chars='01 ...

  5. SQL-26 (二次分组)汇总各个部门当前员工的title类型的分配数目,结果给出部门编号dept_no、dept_name、其当前员工所有的title以及该类型title对应的数目count

    题目描述 汇总各个部门当前员工的title类型的分配数目,结果给出部门编号dept_no.dept_name.其当前员工所有的title以及该类型title对应的数目countCREATE TABLE ...

  6. 进程创建过程详解 CreateProcess

    转载请您注明出处:http://www.cnblogs.com/lsh123/p/7405796.html 0x01 CreateProcessW CreateProcess的使用有ANSI版本的Cr ...

  7. 强化学习10-Deep Q Learning-fix target

    针对 Deep Q Learning 可能无法收敛的问题,这里提出了一种  fix target 的方法,就是冻结现实神经网络,延时更新参数. 这个方法的初衷是这样的: 1. 之前我们每个(批)记忆都 ...

  8. centos/7下安装mysql5.7

    本文参考自:https://blog.csdn.net/fanshujuntuan/article/details/78077433 背景:在ubuntu下用vagrant搭建了一个集群环境, 每个虚 ...

  9. [SpringMVC-值传递] 初始SpringMVC--SpringMVC中的值传递

    把页面中输入的值传递到后台以及后台向前台传递,有以下几种方式 这里以登录为例子,实现打印前端页面的值 1,新建一个控制器,根据不同的请求地址实现不同的请求方式 LoginController.java ...

  10. 理解mpvue的生命周期

    mpvue是美团基于vue开发的一个开发小程序的框架,从而以vue的语法来开发小程序.在生命周期上,mpvue同时支持了vue的生命周期和小程序的生命周期,这可能让新上手的同学费解.这篇文章就来讲讲m ...