H-2028-Lowest Common Multiple Plus
来源:互联网 发布:github编程语言排行榜 编辑:程序博客网 时间:2024/05/22 10:34
Lowest Common Multiple Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32660 Accepted Submission(s): 13294
Problem Description
求n个数的最小公倍数。
Input
输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
Output
为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。
Sample Input
2 4 6
3 2 5 7
Sample Output
12
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32660 Accepted Submission(s): 13294
Problem Description
求n个数的最小公倍数。
Input
输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
Output
为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。
Sample Input
2 4 6
3 2 5 7
Sample Output
12
70
原理:http://www.360doc.com/content/12/0331/14/1313469_199607871.shtml
第一种不好懂╮(╯_╰)╭ 用的第二种
#include<stdio.h>#include<algorithm> #include<iostream>using namespace std;#define maxn 100010int main(){ int T,i,j,k; __int64 a[maxn]; __int64 mul; // 本来定义的int型,显示超时,改为__int64就过了 while(scanf("%d",&T)==1) { mul=1; for(i=0;i<T;i++) { scanf("%d",&a[i]); mul*=a[i]; } for(i=0;i<T;i++) { a[i]=mul/a[i]; } sort(a,a+T); while(a[T-2]) { for(j=0;j<T;j++) { if(a[j]) { k=j; break; } } for(j+=1;j<T;j++) { a[j]=a[j]%a[k]; } sort(a,a+T); } printf("%I64d\n",mul/a[T-1]); } return 0;}
0 0
- H-2028-Lowest Common Multiple Plus
- 2028 Lowest Common Multiple Plus
- 【 2028 Lowest Common Multiple Plus】
- 2028 Lowest Common Multiple Plus
- 2028 Lowest Common Multiple Plus
- [2028 ]: Lowest Common Multiple Plus
- 2028Lowest Common Multiple Plus
- 2028 Lowest Common Multiple Plus
- Lowest Common Multiple Plus
- Lowest Common Multiple Plus
- Lowest Common Multiple Plus
- Lowest Common Multiple Plus
- Lowest Common Multiple Plus
- Lowest Common Multiple Plus
- Lowest Common Multiple Plus
- Lowest Common Multiple Plus
- Lowest Common Multiple Plus
- Lowest Common Multiple Plus
- 去问去问我去
- [HA]负载均衡:HAPROXY与KEEPALIVED强强组合
- 方式的发生法士大夫
- 去问去问去问
- papers
- H-2028-Lowest Common Multiple Plus
- 【畅言】软件工程的根本问题
- hibernate报错
- ORACLE字符串拆分
- 网络IO之阻塞、非阻塞、同步、异步总结
- hdu2026 首字母变大写
- 18岁生日 hdoj 1201
- 收藏母爱
- 把客户当成自己的朋友 (销售中的心理学)