Maximum GCD UVA
来源:互联网 发布:淘宝网店的swot分析 编辑:程序博客网 时间:2024/06/06 08:43
Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possible
pair of these integers.
Input
The first 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 find 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
暴力的gcd ,输入很少见,一直卡在这。。。
// 这个题真是醉了,居然卡在输入上#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<queue>#include<algorithm>#define ll long longusing namespace std;int gcd(int a,int b){ if( a < b) { int tmp = a; a = b; b = tmp; } return b==0? a : gcd(b,a%b); }int a[150];int num[150];int main(){ int n; scanf("%d",&n); getchar(); // 吸收回车 for(int i=0;i<n;i++) { int flag = 1; int cnt = 0; char ch; while( ( ch = getchar() ) != '\n') { if( '0' <= ch && ch <= '9') { ungetc(ch,stdin); // 如果是数字,将它退流 scanf("%d",&a[cnt++]); } } int maxn; maxn = -1; int tmp; for(int j = 0; j < cnt; j ++) for(int k = 0; k < j; k ++) { tmp = gcd( a[j], a[k] ); if( tmp > maxn) maxn = tmp; } printf("%d\n",maxn); } 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
- Maximum GCD UVA
- 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
- Maximum GCD
- Android实现推送方式解决方案
- 欢迎使用CSDN-markdown编辑器
- 性能优化-Bitmap简单处理分析
- 输入的时候被键盘遮挡的问题
- 异构多核处理器开发嵌入式应用入门
- Maximum GCD UVA
- bootstrap中下拉组件没反应
- 随记(1)
- SQLException for SQL [n/a]; SQL state [HY000]; error code [1366];
- 浅谈spring框架(三)
- 怎么让div的高度自适应屏幕的高度
- php学习笔记
- popupWindow,Attempted to finish an input event but the input event receiver has already been dispose
- Ubuntu Java不算费力的安装法