Problem: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

题解:读入的时候处理一下,可以直接读入一个字符串,然后把数再按十进制还原存到数组中,或者直接用ungetc来退回一下。

#include <bits/stdc++.h>
using namespace std;
int a[150];
int main()
{
int n, maxx = -1;
char op;
while(~scanf("%d",&n))
{
while(n --)
{
maxx = -1;
int i = 0;
while(1)
{
scanf("%d",&a[i++]);
while((op=getchar())==' '); // 如果是空格的话用ungetc退格
ungetc(op, stdin);
if(op == '\n') break;
}
for(int j = 0; j < i; j ++)
{
for(int k = j + 1; k < i; k ++)
{
if(__gcd(a[j],a[k]) > maxx) maxx = __gcd(a[j],a[k]);
}
}
printf("%d\n",maxx);
}
}
return 0;
}

Maximum GCD(UVA 11827)的更多相关文章

  1. hdu 1695 GCD(莫比乌斯反演)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  2. 【BZOJ2820】YY的GCD(莫比乌斯反演)

    [BZOJ2820]YY的GCD(莫比乌斯反演) 题面 讨厌权限题!!!提供洛谷题面 题解 单次询问\(O(n)\)是做过的一模一样的题目 但是现在很显然不行了, 于是继续推 \[ans=\sum_{ ...

  3. 【BZOJ2818】Gcd(莫比乌斯反演)

    [BZOJ2818]Gcd(莫比乌斯反演) 题面 Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的 数对(x,y)有多少对. Input 一个整数N Ou ...

  4. 【HDU1695】GCD(莫比乌斯反演)

    [HDU1695]GCD(莫比乌斯反演) 题面 题目大意 求\(a<=x<=b,c<=y<=d\) 且\(gcd(x,y)=k\)的无序数对的个数 其中,你可以假定\(a=c= ...

  5. 求GCD(最大公约数)的两种方式

    求GCD(最大公约数)的两种方式 这篇随笔讲解C++语言程序设计与应用中求GCD(最大公约数,下文使用GCD代替)的两种常用方式:更相减损法和辗转相除法,前提要求是具有小学数学的基本素养,知道GCD是 ...

  6. Codeforces C. Maximum Value(枚举二分)

    题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Maximum GCD (stringstream)题解

    Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possiblepa ...

  8. Codeforces 1092F Tree with Maximum Cost(树形DP)

    题目链接:Tree with Maximum Cost 题意:给定一棵树,树上每个顶点都有属性值ai,树的边权为1,求$\sum\limits_{i = 1}^{n} dist(i, v) \cdot ...

  9. P2257 YY的GCD(莫比乌斯反演)

    第一次做莫比乌斯反演,推式子真是快乐的很啊(棒读) 前置 若函数\(F(n)\)和\(f(d)\)存在以下关系 \[ F(n)=\sum_{n|d}f(d) \] 则可以推出 \[ f(n)=\sum ...

随机推荐

  1. varnish应用

    Nginx+Varnish+基本业务 ngnix nginx.conf配置文件 user root; worker_processes ; error_log logs/error.log crit; ...

  2. Cactus CodeForces - 231E (无向图缩环)

    大意: 给定无向图, 每个点最多属于一个简单环, 多组询问, 求给定起点终点, 有多少条简单路径. 先缩环, 然后假设两点树上路径经过$cnt$个环, 那么答案就为$2^{cnt}$. 要注意缩环建树 ...

  3. el-table el-column selection disable

    几个要点: 1.通过 selectable 绑定 2.绑定的方法只能返回0/1 <el-table-column type="selection" width="5 ...

  4. Centos7--从最小化系统发开发环境

    Centos7--从最小化系统发开发环境 ​程序员总是离不开"环境"的困扰,从进入新手村的那一天就开始手动搞各种环境.虽然阿里云学生服务很方便,但是想弄集群真的买不起.正好实验室有 ...

  5. TypeScript入门四:TypeScript的类(class)

    TypeScript类的基本使用(修饰符) TypeScript类的抽象类(abstract) TypeScript类的高级技巧 一.TypeScript类的基本使用(修饰符) TypeScript的 ...

  6. centos 中 Java环境变量配置

    一.安装java 1.搜索java包 yum search java 2.安装java包 -openjdk.x86_64 3.查看java安装目录 whereis java #找到Java目录 一般在 ...

  7. 文件的空间使用和IO统计

    数据库占用的存储空间,从高层次来看,可以查看数据库文件(数据文件,日志文件)占用的存储空间,从较细的粒度上来看,分为数据表,索引,分区占用的存储空间.监控数据库对象占用的硬盘空间,包括已分配,未分配, ...

  8. TCP-HTTP ___UDP 应用场景

    UDP 套接字应用之广播 import socket,threading #创建套接字 s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) # 设置套接 ...

  9. 移动端设备管理平台 atx server2实践

    目录 1.需求背景 2.初步调研 2.1.云测试平台 2.2.开源工具 2.3.VNC 2.4.企业内部自研云测试平台 3.ATX Server安装 依赖环境 安装rethinkdb 安装atx se ...

  10. nginx+tomcat实现负载均衡以及双机热备

    还记得那些年吗? 还记得更新代码之后,服务器起不来被领导训斥吗?还记得更新代码,需要停机过多的时间被渠道部们埋怨吗?还记得更新代码,代码出错时自己吓个半死吗?于是我们聪明勤快的程序员,看着电影待到夜深 ...