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. Spring.net介绍及MVC中应用

    Spring.net两大核心内容: IOC(控制反转) 传统的面相对象思维模式是对象A依赖对象B,对象B的实例化和调用都在对象A中发生,一旦对象B中发生变化,对象A也要随之变化,这样使得程序间行程了紧 ...

  2. 使用STM32的USART的同步模式Synchronous调戏SPI[2] 【实现spi 9bit】

    [原创出品§转载请注明出处] 出处:http://www.cnblogs.com/libra13179/p/7064533.html 上回说道使用USART的来模拟SPI通讯.说说一下我什么写这个的原 ...

  3. 关于vector变量的size,是一个无符号数引发的bug。LeetCode 3 sum

    class Solution { public: vector<vector<int>> threeSum(vector<int>& a) { vector ...

  4. centos磁盘空间重新分配

    将/home目录压缩一部分空间到/ ref: https://serverfault.com/a/811124/434124 https://stackoverflow.com/a/19969471/ ...

  5. 【388】※ Some useful websites for learning Python

    Ref: Python Tips 1. *args and **kwargs 2. Debugging 3. Generators 4. Map, Filter and Reduce 5. set D ...

  6. [Linux]Linux下动态安装PHP扩展的一般方法(图)

    ---------------------------------------------------------------------------------------------------- ...

  7. shell定时任务crontab

    cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # For details ...

  8. javaweb 学习系列【转】

    http://www.cnblogs.com/xdp-gacl/category/574705.html jsp指令 http://www.cnblogs.com/huiyuantang/p/5332 ...

  9. C#中Graphics的画图代码【转】

    我要写多几个字上去 string str = "Baidu"; //写什么字? Font font = Font("宋体",30f); //字是什么样子的? B ...

  10. hdu3189-Just Do It-(埃氏筛+唯一分解定理)

    Just Do It Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...