HDU2028:Lowest Common Multiple Plus
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的更多相关文章
- 最大公约数最小公倍数 (例:HDU2028 Lowest Common Multiple Plus)
也称欧几里得算法 原理: gcd(a,b)=gcd(b,a mod b) 边界条件为 gcd(a,0)=a; 其中mod 为求余 故辗转相除法可简单的表示为: int gcd(int a, int b ...
- hdu 2028 Lowest Common Multiple Plus(最小公倍数)
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- Lowest Common Multiple Plus
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 【九度OJ】题目1439:Least Common Multiple 解题报告
[九度OJ]题目1439:Least Common Multiple 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1439 ...
- 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 ...
- 题目1439:Least Common Multiple(求m个正数的最小公倍数lcm)
题目链接:http://ac.jobdu.com/problem.php?pid=1439 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- 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 ...
- 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 ...
- ACM1019:Least Common Multiple
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
随机推荐
- 小程序证书申请FAQ
1. 帮别人开发小程序, 先把你的微信号加到成员里, 并给予开发者权限,体验者权限,登录,数据分析,开发管理,开发设置 2. 需要https, 不能用windows2003,必须2008以上,用IIS ...
- CentOS查询系统版本
1.cat /proc/version 2.cat /etc/redhat-release 3.cat /proc/version 4.uname -a
- Spring Boot整合@Scheduled定时计划
原文地址:https://blog.csdn.net/justry_deng/article/details/80666508 修改部分: SpringBoot集成了@Scheduled的相关依赖(o ...
- learning scala control statement
1 .if satement 与其它语言不同的是,scala if statement 返回的是一个值 scala> val a = if ( 6 > 0 ) 1 else -1a: In ...
- C#中使用FFMPEG切割、合并视频。
参考网址:https://blog.csdn.net/samwang_/article/details/70332924 使用前先确保电脑已经安装了FFMPEG,并且配置好环境变量.检测是否安装配置好 ...
- C++ string类insert用法总结
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- Java 面向对象的三大特性之一 继承
继承: Java是继承的三大特性之一,是Java中实现代码重用的手段之一 将重复的代码抽取到父类中继承的有点或者现实 优点: 方便修改代码 减少代码量 Java中继承的语法: 修饰符 SubClass ...
- 网口扫盲二:Mac与Phy组成原理的简单分析(转)
1. general 下图是网口结构简图.网口由CPU.MAC和PHY三部分组成.DMA控制器通常属于CPU的一部分,用虚线放在这里是为了表示DMA控制器可能会参与到网口数据传输中. 对于上述的三部分 ...
- DevExpress ASP.NET v18.2新功能详解(四)
行业领先的.NET界面控件2018年第二次重大更新——DevExpress v18.2日前正式发布,本站将以连载的形式为大家介绍新版本新功能.本文将介绍了DevExpress ASP.NET Cont ...
- Docker常用命令学习
sudo service docker startsudo docker run hello-worlddocker stats --helpdocker run -d -P training/web ...