UVA 11827Maximum GCD
来源:互联网 发布:手机壳效果图软件 编辑:程序博客网 时间:2024/05/22 23:00
F - Maximum GCD
Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Given the N integers, you have to nd the maximum GCD (greatest common divisor) of every possible
pair of these integers.
Input
The rst line of input is an integer N (1 < N < 100) that determines the number of test cases.
The following N lines are the N test cases. Each test case contains M (1 < M < 100) positive
integers that you have to nd the maximum of GCD.
Output
For each test case show the maximum GCD of every possible pair.
Sample Input
3
10 20 30 40
7 5 12
125 15 25
Sample Output
20
1
25
题目很水 暴力就能过 难点在如何输入没有停止的数
#include <iostream>#include <string.h>#include <stdio.h>#include <math.h>#include <stdlib.h>#include <sstream>using namespace std;int gcd (int a,int b){ if(b==0) return a; else return gcd(b,a%b);}int main(){ int i,j,n,t,a[105]; cin>>t; getchar(); while(t--) { //getchar(); memset(a,0,sizeof(a)); string str; getline(cin,str); stringstream stream(str); int n=0; while(stream>>a[n]) { n++; } int ans=1; for(i=0;i<n;i++) for(j=i+1;j<n;j++) ans=max(gcd(a[i],a[j]),ans); cout<<ans<<endl; } return 0;}
0 0
- UVA 11827 Maximum GCD gcd
- UVa 11827 Maximum GCD
- UVA 11827-Maximum GCD
- UVa 11827 - Maximum GCD
- UVA 11827 - Maximum GCD
- UVA 11827 Maximum GCD
- UVa 11827 Maximum GCD
- UVA 11827Maximum GCD
- UVA 11827 Maximum GCD
- UVA 11827 Maximum GCD
- UVa 11827 Maximum GCD (gcd&读入技巧)
- UVA 11827 Maximum GCD gcd 读入技巧
- UVA 11827 Maximum GCD【GCD,stringstream】
- UVA 11827 Maximum GCD(gcd, getline)
- Uva——11827 Maximum gcd
- Maximum GCD UVA
- Maximum GCD - UVa 11827 最大公约数 读入有坑
- UVA - 11827 - Maximum GCD,10200 - Prime Time (数学)
- LightOJ 1197 Help Hanzo(区间素数筛选)
- c 4.5 k-means 算法 机器学习
- Kylin, Mondrian, Saiku系统的整合
- LightOJ1336 Sigma Function(约数和为奇数的个数)
- 数位DP问题
- UVA 11827Maximum GCD
- LightOJ 1234Harmonic Number
- Android 中Timer和TimeTask完成定时任务
- SGU 106The equation
- HDU 1452 Happy 2004
- eclipse 使用Maven deploy命令部署构建到Nexus上
- POJ 2478 Farey Sequence(欧拉函数前n项和)
- hibernate 数据库操作模板
- 自定义枚举以及如何在反射中获取枚举值