zzulioj 1806: n个数的最小公倍数 (GCD)
2015-12-09 13:49
260 查看
1806: n个数的最小公倍数
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 188 Solved: 100
SubmitStatusWeb
Board
Description
给定n个数字,求这n个数字的最小公倍数。Input
输入分两行,第一行是一个n,代表有n个数字,接着第二行输入n个数字,数字均在int范围内Output
输出这n个数字的最小公倍数,保证结果在int范围内Sample Input
31 2 3
Sample Output
6#include<stdio.h> #include<string.h> #include<algorithm> #define INF 0x3f3f3f3f #define N 1010 #define ll long long using namespace std; int a ; ll gcd(ll x,ll y) { ll t; if(x<y){t=x;x=y;y=t;} return y?gcd(y,x%y):x; } int main() { int n,i,j; ll sum; while(scanf("%d",&n)!=EOF) { sum=1; for(i=1;i<=n;i++) { scanf("%d",&a[i]); sum=sum*a[i]/gcd(sum,a[i]); } printf("%lld\n",sum); } return 0; }
相关文章推荐
- Microsoft Azure Tools: Failed to initialize Microsoft Azure storage emulator. The storage emulator n
- 格式化输出(printf,sprintf)
- Linux core 文件介绍
- 【数据结构算法】——内部排序整理总结
- Jquery获得url的参数
- 使用 IntelliJ IDEA 开发一般 Java 应用程序时配置 Allatori 进行代码混淆
- onTextChanged参数解释及实现EditText字数监听
- 汉诺塔问题
- Josephus问题解决方法五(递归)
- windows误删文件恢复
- Web安全:XSS的原理分析与解剖
- Mysql中普通的索引、主键、唯一、全文索引的区别
- HDU 4757 Tree 可持久化字典树
- 用基础动画实现iOS控件循环旋转
- request使用getReader()和getInputStream()获取请求参数报400错误
- 博客收集
- 【原创】Oracle实现PGSQL的generate_series
- Linux 下编译及调试 C 代码的简易指南
- Android-多线程
- 内容分发平台个性化推荐系统经验简单总结