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. Struts2版本更新报错:>>> ActionContextCleanUp <<< is deprecated! Please use the new filters!

    因低版本Struts2存在漏洞,更新为较新的版本.启动时,报如下警告信息: ************************************************************** ...

  2. iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址(2014年2月19日更新版)

    //转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3496069.html     编号 iOS-Apple苹果官方文档翻译名称 博文链接地址 ...

  3. 2017 ACM暑期多校联合训练 - Team 4 1012 HDU 6078 Wavel Sequence (模拟)

    题目链接 Problem Description Have you ever seen the wave? It's a wonderful view of nature. Little Q is a ...

  4. 详解H5中的history单页面,手动实现单页面开发,细说h5单页面原理

    就目前来看,前端的单页面开发占了很大一部分,一方面无刷新的切换增强了体验,并且浏览器记录依然存在,前进后退都没问题,在之前我们通地址栏中的hash改变来触发onhashchange方法来实现单页面应用 ...

  5. Entity Framework(EF的Database First方法)

    EntityFramework,是Microsoft的一款ORM(Object-Relation-Mapping)框架.同其它ORM(如,NHibernate,Hibernate)一样, 一是为了使开 ...

  6. 【译】第二篇 SQL Server代理作业步骤和子系统

    本篇文章是SQL Server代理系列的第二篇,详细内容请参考原文. SQL Server代理作业由一系列的一个或多个作业步骤组成.一个作业步骤分配给一个特定的作业子系统(确定作业步骤去完成的工作). ...

  7. perl6 登录phpmyadmin

    use HTTP::UserAgent; my $ua = HTTP::UserAgent.new; my $url = 'http://localhost/phpMyAdmin/index.php' ...

  8. [Leetcode] Longest Palindromic Subsequence

    Longest Palindromic Subsequence 题解 题目来源:https://leetcode.com/problems/longest-palindromic-subsequenc ...

  9. CSS3 object-fit 图像裁剪

    MDN定义 https://developer.mozilla.org/zh-CN/docs/Web/CSS/object-fit 该 object-fit CSS 属性指定替换元素的内容应该如何适应 ...

  10. 打开exls表格时报‘向程序发送命令是出现问题’的错误的解决方法

    1.问题现象 打开表格文件时系统报如下错误 2.解决方法 1)按照如下方法找到excel选项,点击进入 2)找到‘忽略使用动态数据交换(DDE)的其它应用程序(O)',去掉复选框种的勾,点击确定,重新 ...