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<map>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; const int INF=1e9+7;
const int maxn=1010;
typedef long long ll; int t;
string str;
int a[maxn]; int gcd(int a,int b)
{
return b?gcd(b,a%b):a;
} int main()
{
scanf("%d\n",&t);
while(t--)
{
int i,j,maxx=0;
getline(cin,str);
stringstream ss(str);
int n=0;
while(ss>>a[n])
n++;
for(i=0; i<n-1; i++)
for(j=i+1; j<n; j++)
maxx=max(maxx,gcd(a[i],a[j]));
printf("%d\n",maxx);
}
return 0;
} //方法二
int gcd(int a,int b)
{
return b?gcd(b,a%b):a;
}
int main()
{
int T;
int a[105];
char c;
scanf("%d",&T);
while (getchar() != '\n');
while(T--)
{
int cnt=0;
while((c=getchar())!='\n')
{
if(c>='0' && c<='9')
{
ungetc(c,stdin);//将字符c退回到输入流中
scanf("%d",&a[cnt++]);
}
}
int max=0;
for(int i=0; i<cnt-1; i++)
{
for(int j=i+1; j<cnt; j++)
{
int t=gcd(a[i],a[j]);
if(t>max) max=t;
}
}
printf("%d\n",max);
}
return 0;
}

邝斌带你飞之数论专题--Maximum GCD UVA - 11827的更多相关文章

  1. Kuangbin 带你飞-基础计算几何专题 题解

    专题基本全都是模版应用.贴一下模版 平面最近点对 const double INF = 1e16; ; struct Point { int x,y; int type; }; double dist ...

  2. Kuangbin 带你飞-线段树专题 题解

    HDU 1166 敌兵布阵 单调更新区间查询和 #include <map> #include <set> #include <list> #include < ...

  3. 【kuangbin带你飞】 MST专题

    唉,被班级合唱和复变考试搞得心力交瘁.新算法学不进去,更新下吧 A - Til the Cows Come Home The Head Elder of the tropical island of ...

  4. [kuangbin带你飞]专题1-23题目清单总结

    [kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...

  5. ACM--[kuangbin带你飞]--专题1-23

    专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find T ...

  6. KUANGBIN带你飞

    KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //201 ...

  7. 「kuangbin带你飞」专题十四 数论基础

    layout: post title: 「kuangbin带你飞」专题十四 数论基础 author: "luowentaoaa" catalog: true tags: mathj ...

  8. 【算法系列学习三】[kuangbin带你飞]专题二 搜索进阶 之 A-Eight 反向bfs打表和康拓展开

    [kuangbin带你飞]专题二 搜索进阶 之 A-Eight 这是一道经典的八数码问题.首先,简单介绍一下八数码问题: 八数码问题也称为九宫问题.在3×3的棋盘,摆有八个棋子,每个棋子上标有1至8的 ...

  9. 「kuangbin带你飞」专题二十 斜率DP

    layout: post title: 「kuangbin带你飞」专题二十 斜率DP author: "luowentaoaa" catalog: true tags: mathj ...

随机推荐

  1. 批量提取图片主要3个颜色匹配中文名字并写入到excel设置对应颜色的背景

    from gevent import monkey monkey.patch_all() import gevent from haishoku.haishoku import Haishoku im ...

  2. JVM学习四:JVM之类加载器之初始化分析

    在经过了前面的加载  和 连接分析之后,这一节我们进入重要的初始化分析过程: 一.认识初始化 初始化:这个似乎与上面的初始化为默认值有点矛盾,我们再看一遍:为累的静态变量赋予正确的初始值,上面是赋予默 ...

  3. java对象与json互转

    package com.liveyc; import java.io.StringWriter; import org.junit.Test; import com.fasterxml.jackson ...

  4. 在Unity中实现屏幕空间反射Screen Space Reflection(4)

    第四部分讲一下如何在2D屏幕空间步进光线. http://casual-effects.blogspot.com/2014/08/screen-space-ray-tracing.html 中的代码感 ...

  5. 【洛谷 P3648】 [APIO2014]序列分割 (斜率优化)

    题目链接 假设有\(3\)段\(a,b,c\) 先切\(ab\)和先切\(bc\)的价值分别为 \(a(b+c)+bc=ab+bc+ac\) \((a+b)c+ab=ab+bc+ac\) 归纳一下可以 ...

  6. JWT 拓展

    JWT适用场景 https://www.jianshu.com/p/af8360b83a9f 适用于一次性操作的认证,颁布一个很短过期时间的JWT给浏览器. 无状态的JWT无法实现精确的在线人数统计. ...

  7. Tensorflow常用函数说明(一)

    首先最开始应该清楚一个知识,最外面的那个[ [ [ ]]]括号代表第一维,对应维度数字0,第二个对应1,多维时最后一个对应数字-1:因为后面有用到 1 矩阵变换 tf.shape(Tensor) 返回 ...

  8. perl6 HTTP::UserAgent (3) JSON

    如果一个 URL 要求POST数据是 JSON格式的, 那我们要怎么发送数据呢? 第一种: HTTP::Request 上一篇说到, 发送 POST 数据, 可以: . $ua.post(url, % ...

  9. Skip List(跳跃表)原理详解与实现【转】

    转自:http://dsqiu.iteye.com/blog/1705530 Skip List(跳跃表)原理详解与实现 本文内容框架: §1 Skip List 介绍 §2 Skip List 定义 ...

  10. Power Profiles for Android

    http://source.android.com/devices/tech/power.html Battery usage information is derived from battery ...