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 ...
随机推荐
- echo * 打印当前目录列表
所以在脚本中 类似 echo $a* 如果$a为空 则会打印 目录列表.
- Linux第三周作业
1.三个法宝 ①存储程序计算机工作模型,计算机系统最最基础性的逻辑结构: ②函数调用堆栈,堆栈完成了计算机的基本功能:函数的参数传递机制和局部变量存取 : ③中断,多道程序操作系统的基点,没有中断机制 ...
- nyoj 0269 VF(dp)
nyoj 0269 VF 意思大致为从1-10^9数中找到位数和为s的个数 分析:利用动态规划思想,一位一位的考虑,和s的范围为1-81 状态定义:dp[i][j] = 当前所有i位数的和为j的个数 ...
- laravel中对模型和路由做缓存,提高性能
模型缓存命令: php think optimize:schema 路由缓存命令: php think optimize:route
- shell script auto generate the relevant header information
first : add follow context in /etc/vim/vimrc set ignorecaseset cursorlineset autoindentautocmd Buf ...
- 人机交互之QQ拼音
随着电脑系统的不断更新,电脑自带的系统输入法也越来越适应广大群众了,那为什么其他的输入法还能占有大量的用户呢? 首先系统输入法是面向大众的,个性化方面略显不足. 其次系统输入法功能不够全面,比如说手写 ...
- Uva LV 2995 Image Is Everything 模拟,坐标映射,视图映射 难度: 1
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- Could not load driverClass ${driverClassName} 的解决方案
对项目进行ssm整合的过程中,发现报这个错误:Could not load driverClass ${driverClassName} 不明所以,在网上找了半天,各种答案都有,最后终于找 ...
- XML(二)
XML XML介绍 1.什么是xml? 概念:XML(EXtensible Markup Language)XML 指可扩展标记语言(EXtensible Markup Language) 可扩展:我 ...
- JavaWeb基础-认识JavaWeb
程序开发体系 B/S 浏览器/服务器 开发维护成本低 客户端负载低 安全性低 C/S 客户端/服务器 成本高 客户端负载高 安全性高 javaweb简介 静态网页 HTML CSS,人浏览的数据是始终 ...