Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possiblepair 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) positiveintegers 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,之前小紫看到的stringstream可以拿出来用了,很方便啊,这里就用到了这个技巧

代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<iostream>
#include<algorithm>
#include<sstream>
#define INF 0x3f3f3f3f
#define ll long long
const int N=16005;
const ll MOD=998244353;
using namespace std;
ll gcd(ll a,ll b){
return b==0? a:gcd(b,a%b);
}
int main(){
int n;
ll num[110],x,MAX=-100000000;
string s;
scanf("%d",&n);
getchar();
while(n--){
getline(cin,s);
int sum=0;
MAX=-100000000;
stringstream ss(s);
while(ss>>x){
num[sum++]=x;
}
for(int i=0;i<sum;i++){
for(int j=i+1;j<sum;j++){
MAX=max(MAX,gcd(num[i],num[j]));
}
}
cout<<MAX<<endl;
}
return 0;
}

Maximum GCD (stringstream)题解的更多相关文章

  1. UVA 11827 Maximum GCD

    F - Maximum GCD Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Given the ...

  2. 邝斌带你飞之数论专题--Maximum GCD UVA - 11827

    Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possible p ...

  3. Maximum GCD(UVA 11827)

    Problem:Given the N integers, you have to find the maximum GCD (greatest common divisor) of every po ...

  4. Codeforces Round #651 (Div. 2) A Maximum GCD、B GCD Compression、C Number Game、D Odd-Even Subsequence

    A. Maximum GCD 题意: t组输入,然后输入一个n,让你在区间[1,n]之间找出来两个不相等的数a,b.求出来gcd(a,b)(也就是a,b最大公约数).让你求出来最大的gcd(a,b)是 ...

  5. Maximum GCD(fgets读入)

    Maximum GCD https://vjudge.net/contest/288520#problem/V Given the N integers, you have to find the m ...

  6. UVA - 11827 - Maximum GCD,10200 - Prime Time (数学)

    两个暴力题.. 题目传送:11827 Maximum GCD AC代码: #include <map> #include <set> #include <cmath> ...

  7. UVA11827 Maximum GCD

    /* UVA11827 Maximum GCD https://vjudge.net/contest/153365#problem/V 数论 gcd 水题,然而读入比较坑 * */ #include ...

  8. Codeforces Round #651 (Div. 2) A. Maximum GCD(数论)

    题目链接:https://codeforces.com/contest/1370/problem/A 题意 有 $n$ 个数大小分别为 $1$ 到 $n$,找出两个数间最大的 $gcd$ . 题解 若 ...

  9. Codeforces Round #651 (Div. 2) A. Maximum GCD (思维)

    题意:在\(1\)~\(n\)中找两个不相等的数使得他们的\(gcd\)最大. 题解:水题,如果\(n\)是偶数,那么一定取\(n\)和\(n/2\),\(n\)是奇数的话,取\(n-1\)和\((n ...

随机推荐

  1. FS Shell命令手册

    1.       FS Shell 1.1     简介 调用文件系统(FS)Shell命令应使用 bin/hadoop fs <args>的形式. 所有的的FS shell命令使用URI ...

  2. Loadrunner 手动关联技术

    录制成功,回放失败,怀疑和动态数据有关: 1 重新录制一份脚本,两次录制的脚本进行比对,确定动态数据,复制动态数据: 2  找到第一次产生该动态数据的响应对应的相应请求: 1)  拷贝脚本中适当长度的 ...

  3. pythonon ddt数据驱动二(json, yaml 驱动)

    这一篇主要是关于文件的数据驱动. 一.通过json文件驱动 @ddt class MyTest(unittest.TestCase): @file_data('test_data_list.json' ...

  4. Docker Quickstart Terminal: exit status 255 解决办法

    原文地址:https://www.jianshu.com/p/061f1ae69937 初识docker,还有先拿Windows 7 尝试下,官方提供了docker toolbox,下载后一键安装,桌 ...

  5. .NET RSA解密、签名、验签

    using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Sec ...

  6. 筛选DataTable中的数据

    DataTable dt = bll.GetTable(); //查询数据 DataTable newdt = new DataTable(); //一个新的table来保存筛选的记录 newdt = ...

  7. 来自阿里妈妈的iconfont(转)

    转自http://www.augsky.com/775.html 随便说说两者的优缺点 其实主要是说iconfont的优点和Font Awesome的缺点.-_-|||iconfont的图标库相当巨大 ...

  8. CAS机制

    ##################################################################### 我们知道多线程操作共享资源时,会出现三个问题:可见性.有序性 ...

  9. python3.4学习笔记(十九) 同一台机器同时安装 python2.7 和 python3.4的解决方法

    python3.4学习笔记(十九) 同一台机器同时安装 python2.7 和 python3.4的解决方法 同一台机器同时安装 python2.7 和 python3.4不会冲突.安装在不同目录,然 ...

  10. 用CSS让字体在一行内显示不换行

    青枫 , 2012/07/13 18:08 , css样式设计 , 评论(0) , 阅读(2189) , Via 本站原创 大 | 中 | 小  当一行文字超过DIV或者Table的宽度的时候,浏览器 ...