hud 1019最小公倍数
2015-11-19 21:47
357 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1019
思路:头两个数先求,再用所求的数与后面的一个数求,依次类推
思路:头两个数先求,再用所求的数与后面的一个数求,依次类推
#include<stdlib.h> #include<time.h> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <ctime> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <map> #include <set> #include <string.h> using namespace std; int n,m; int arr[1000]; int gcd(int a,int b) { if(b) return gcd(b,a%b); else return a; } int lcm(int a,int b) { return a/gcd(a,b)*b; //此处不能用a*b/gcd(a,b)数据会溢出 } int main() { while(scanf("%d",&n)!=EOF) { while(n--) { scanf("%d",&m); int t; scanf("%d",&t); for(int i=1;i<=m-1;i++) { scanf("%d",&arr[i]); t=lcm(t,arr[i]); } printf("%d\n",t); } } return 0; }
相关文章推荐
- 【转载】COM 组件设计与应用(三)——数据类型
- 简单算术表达式计算器
- VTK6.2 Qt5.4.0 VS2013
- JS对象与json字符串格式转换实例
- Relativelayout布局属性大全,包含大部分的属性解释
- Centos下搭建redis缓存数据库
- HDU 1698 Just a Hook【线段树】区间修改,查询总和
- Qt5网络与通信
- 6. Spring MVC 4.1-服务器端推送
- Mahjong
- 启发式搜索A * 算法
- Linux ftp配置 以及 权限配置
- 使用Gallery创建向导表单
- java界面windowbuilder
- java中数组和集合的互相转换
- Android开发 ActivityGroupd应用底部导航栏
- 12.C#的函数
- 换肤效果
- 2015 重庆市赛 解题报告
- flash buidler 4.7 真机调试