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. nginx压缩,缓存

    https://www.darrenfang.com/2015/01/setting-up-http-cache-and-gzip-with-nginx/ https://www.linuxdashe ...

  2. Java工具类DateFormatUtils详解

    日期和时间格式化实用程序和常量public static String format(Calendar calendar, String pattern) 说明:将日历格式化为特定的模式:参数:cal ...

  3. opencv-3.3安装记录-ubuntu 14.04

    这个二逼问题不会是最后一次. ipcv-****.tar.gz 这个文件在cmake的时候会卡住,这里先下载这个文件,大概38M,放到.cache/ippcv目录下就可以了.貌似还需要改下名字. 就可 ...

  4. UNITY 多个子MESH与贴图的对应关系

    多个贴图时,与子MESH一一对应,如果多了 ...还待研究如何对应

  5. java由字符型强制转化为整型例题

    此Java程序依次输出参数,参数类型为字符型,要求更改程序,使得字符型强制转化为整形,并将这些整数相加,最后输出总和. 原程序: package demo; public class CommandP ...

  6. How to Pronounce the Days of the Week

    How to Pronounce the Days of the Week Share Tweet Share Vocabulary study:  how to pronounce the days ...

  7. Java动态代理的两种实现方法

    注:文章转载自:https://blog.csdn.net/m0_38039437/article/details/77970633 一.代理的概念 动态代理技术是整个java技术中最重要的一个技术, ...

  8. 手工获取AWR报告

    AWR(Automatic Workload Repository)报告常用于Oracle数据库性能分析.熟练解读AWR报告有助于快速分析Oracle性能问题.下面主要描述如何手工获取AWR报告. 操 ...

  9. FBackup:个人用途与商业用途都是免费的

    當自己在備份電腦資料時,若沒有使用備份及還原軟體時,我想很多人的作法就是「想到應該要備份了,然後進行備份檔案的壓縮.壓縮好之後複製到不同的磁碟機或燒錄光碟」,等要用的時候,再拿出來還原.若是這樣,其實 ...

  10. windows下配置mysql环境变量 - 使用cmd访问mysql(图)

    window7为例,右击“计算机” - 单击“属性” - 单击“高级系统设置” - 单击“环境变量”,剩下看图: <图1> 右下角"环境变量". <图2>选 ...