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. ChinaTest测试感悟

    这次去北京参加ChinaTest大会,听了各位大师和同行的心得和感悟,收获颇多.很喜欢这样的大会,可以听到测试的各种声音各种观点.当没有对错时,需要思考的就是怎样采取最适合当前环境的策略.言归正传,谈 ...

  2. django的contenttype表

    https://blog.csdn.net/aaronthon/article/details/81714496 这篇文章已经非常详细了,供自己以后忘了...回看...... 总结: 当一张表和多个表 ...

  3. hibernate注解(一)JoinColumn

    @Entity @Table(name="t_group") public class Group { private int id; private String name; p ...

  4. [py]flask从0到1-模板/增删改查

    flask知识点 1.后端渲染html到前端 render_template 2.后端获取前端数据 request.args.get 3.前端获取后端数据 模板 4.警示消息 flash {{ get ...

  5. SQLAlchemy技术文档(中文版)(全)

    原文链接:http://www.cnblogs.com/iwangzc/p/4112078.html(感谢作者的分享) sqlalchemy 官方文档:http://docs.sqlalchemy.o ...

  6. 十四、springboot全局处理异常(@ControllerAdvice + @ExceptionHandler)

    1.@ControllerAdvice 1.场景一 在构建RestFul的今天,我们一般会限定好返回数据的格式比如: { "code": 0, "data": ...

  7. POJ1014:Dividing(多重背包)

    http://poj.org/problem?id=1014 Description Marsha and Bill own a collection of marbles. They want to ...

  8. tf.nn.embedding_lookup函数的用法

    关于np.random.RandomState.np.random.rand.np.random.random.np.random_sample参考https://blog.csdn.net/lanc ...

  9. 一个新人对HTML的理解

    首先 HTML里面包含的东西是什么? 在HTML里面   注释的表示方式是    <!--注释内容--> 注释 HTML初始默认包含了两大部分: 一部分是 <head>< ...

  10. 原生http模块与使用express框架对比

    node的http创建服务与利用Express框架有何不同 原生http模块与使用express框架对比: const http = require("http"); let se ...