Maximum GCD

https://vjudge.net/contest/288520#problem/V

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

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 10000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=1e9+;
const double oula=0.57721566490153286060651209;
using namespace std; int n;
char str[];
vector<int>ve; int main(){
scanf("%d%*c",&n);
for(int i=;i<=n;i++){
fgets(str,sizeof(str),stdin);
ve.clear();
int co=;
int len=strlen(str);
for(int j=;j<len;j++){
if(str[j]>=''&&str[j]<=''){
co=co*+str[j]-'';
}
else{
if(co)
ve.pb(co);
co=;
}
}
if(co){
ve.pb(co);
}
int ans=;
for(int i=;i<ve.size();i++){
for(int j=i+;j<ve.size();j++){
ans=max(ans,__gcd(ve[i],ve[j]));
}
}
printf("%d\n",ans);
}
}

Maximum GCD(fgets读入)的更多相关文章

  1. UVA11827 Maximum GCD

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

  2. Maximum GCD(UVA 11827)

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

  3. UVA 11827 Maximum GCD

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

  4. Maximum GCD (stringstream)题解

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

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

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

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

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

  7. 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)是 ...

  8. UVA 11827 Maximum GCD (输入流)

    题目:传送门 题意:求n个数的最大公约数,暴力不会超时,难点在没有个数控制的输入. 题解:用特殊方法输入. #include <iostream> #include <cmath&g ...

  9. UVA 11827 Maximum GCD【GCD,stringstream】

    这题没什么好说的,但是输入较特别,为此还WA了一次... 题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge& ...

随机推荐

  1. mongodb学习-练习实例

    C:\Users\issuser>mongoMongoDB shell version: 2.4.6connecting to: test> db.user.find(){ "_ ...

  2. python 阿狸的进阶之路(7)

    面向对象 转自林海峰的博客  http://www.cnblogs.com/linhaifeng/articles/6182264.html 面向对象的理解: 将数据分类,比如学生类.数据有关的函数, ...

  3. Mac下的SecureCRT使用技巧

    1.secureCRT session manager 怎么添加到标题栏里? Options - Global Options - General 把 Use dockable session man ...

  4. mysql主从复制搭建中几种log和pos详解

    一.主从原理 Replication 线程   Mysql的 Replication 是一个异步的复制过程,从一个 Mysql instace(我们称之为 Master)复制到另一个 Mysql in ...

  5. Spring+Quartz 实现定时任务的配置方法

    Spring+Quartz 实现定时任务的配置方法 整体介绍 一.Quartz介绍 在企业应用中,我们经常会碰到时间任务调度的需求,比如每天凌晨生成前天报表,每小时生成一次汇总数据等等.Quartz是 ...

  6. 那些年,我们追过的PHP自加自减运算(1)

    ------------------------------------------------------------------------------------------- PHP的运算符号 ...

  7. 关于在VS2008和VS2010中禁用及卸载Visual Assist X的方法研究——转载

    禁用和启用   此方法对于VS2008和VS2010 都适用. 在VS2008或VS2010菜单栏中选择“VassistX”选项卡,找到“Enable/Disable Visual Assist X” ...

  8. Canvas中 drawImage绘制图片不显示

    在学习 html5中的 Canvas.drawImage时写了如下代码: <!doctype html> <html> <head><title>研究& ...

  9. C# CefSharp MemoryStreamResponseFilter这个类使用过程中遇到的bug,dataIn.CopyTo(dataOut)异常

    使用这个类,可以获取请求的所有数据,可用来下载网站的图片.js等 cef给出的源码 dataIn.CopyTo(dataOut);这句代码,有时候会有问题.问题是这个:dataIn.length 会大 ...

  10. php yii 命令

    php yii 敲回车 This is Yii version 2.0.11. The following commands are available: - asset Allows you to ...