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. Python【列表 字典 元组】

    列表列表用中括号[ ]把各种数据框起来,每一个数据叫作“元素”.每个元素之间都要用英文逗号隔开各种类型的数据(整数/浮点数/字符串)————————————————————————————从列表提取单 ...

  2. 14.shell脚本学习

    简单的执行跟踪,会使得Shell显示每个被执行到的命令sh -x delete.sh 查找与替换grepsed -i "s/t_rs_customer/t_rs_customer_bak/g ...

  3. oracle数据库的冷备份

    前言 冷备份是Oracle最简单的一种备份,所谓的冷备份指的就是在关闭数据库实例的情况下进行数据库备份操作的实现:然后使用操作系统实用工具或者第三方工具备份所有相关的数据库文件.能简单快速地备份.能简 ...

  4. hdu 6077多校签到

    #include <iostream> #include <cstdio> using namespace std; ][]; int f(int pos) { ; ;i< ...

  5. VS219 没有.net core 3.0模板

    控制台命令 dotnet --info dotnet --version 都正常显示有安装3.0 需要升级VS 2019 16.3.3,本地版本为16.3.2

  6. Task资料

    5天玩转C#并行和多线程编程:http://www.cnblogs.com/yunfeifei/p/3993401.html

  7. php对象转换为数组的部分代码

    function object_array($array){ if(is_object($array)){ $array = (array)$array; } if(is_array($array)) ...

  8. Oracle设置权限和还原数据库

    Oracle还原数据库 ,在最高权限账户上,先将安装好的数据上创建一个账户 -- Create the user create user newsafe identified by newsafe d ...

  9. Linux与Windows的设备驱动模型对比

    Linux与Windows的设备驱动模型对比 名词缩写: API 应用程序接口(Application Program Interface ) ABI 应用系统二进制接口(Application Bi ...

  10. K2 BPM_如何将RPA的价值最大化?_全球领先的工作流引擎

     自动化技术让企业能够更有效的利用资源,减少由于人为失误而造成的风险损失.随着科技的进步,实现自动化的途径变得更加多样化. 据Forrester预测,自动化技术将在2019年成为引领数字化转型的前沿技 ...