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. Java并发机制及锁的实现原理

    同步的基本思想 为了保证共享数据在同一时刻只被一个线程使用,我们有一种很简单的实现思想,就是 在共享数据里保存一个锁 ,当没有线程访问时,锁是空的. 当有第一个线程访问时,就 在锁里保存这个线程的标识 ...

  2. JavaScrip(三)JavaScrip变量高级操作(字符串,数组,日期)

    一:字符串 charAt() 返回指定位置的字符 indexof() 返回指定字符串首次出现的位置 replace() 替换指定的字符 concat() 连接两个或多个字符串 substr(start ...

  3. Mybatis的二级缓存注意点

    --声明:一下内容都不一定是正确的,只是自己测试的结果,请自己的动手操作得出自己的结论 1.开启Mybatis的二级缓存,不仅要在SqlMapConfig.xml中进行开启总开关,还要在对应的XXXM ...

  4. .net core json配置相关用法

    在.net core中,配置文件差不多都是json文件.我们在开发程序的时候,可以使用系统默认的appsettings.json,可以自定义json配置文件.当json配置文件里面的参数改变时,程序也 ...

  5. python安装与初始

    第一天学习中了解到python是高级语言,和java.PHP性质相同,而c语言.汇编属于低级语言,而高级语言与低级语言的区别,很重要的一点在于内存的处理上,低级语言在调用内存时需要自己编程来控制程序内 ...

  6. Dom操作注意事项

    Dom操作注意事项 基本概念: 在 HTML DOM (文档对象模型)中,每个部分都是节点: 文档本身是文档节点 所有 HTML 元素是元素节点 所有 HTML 属性是属性节点 HTML 元素内的文本 ...

  7. 延迟载入Dll(动态载入Dll)

    windows核心编程(第五版)20.3节的延迟载入Dll 延迟载入Dll技术出现的原因: 因为DLL的加载是比较浪费时间的,特别是大型软件加载,因此,这项技术是在应对软件初始化过程中避免浪费太多的时 ...

  8. <Dr.Elephant><How to tune ur application>

    Why Dr.Elephant? Most of Hadoop optimization tools out there, but they are focused on simplifying th ...

  9. ESP8266 上报数据到贝壳物联

    下面贴上代码: #include <aJSON.h> #include <SPI.h> #include <Wire.h> #include <dht11.h ...

  10. SpringSecurity自定义登陆页面和跳转页面

    如果我们不用form-login说明登陆界面,springsecurity框架将自动为我们生成登陆界面 现在我们不想用自动生成的登陆界面了,而想使用自定义的漂亮的登陆界面 则需要使用<secur ...