F - Maximum GCD

Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Given the N integers, you have to nd the maximum GCD (greatest common divisor) of every possible
pair of these integers.
Input
The rst 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 nd 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 <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <sstream>
using namespace std;
int gcd (int a,int b)
{
if(b==)
return a;
else
return gcd(b,a%b);
}
int main()
{
int i,j,n,t,a[];
cin>>t;
getchar();
while(t--)
{
//getchar();
memset(a,,sizeof(a));
string str;
getline(cin,str);
stringstream stream(str);
int n=;
while(stream>>a[n])
{
n++;
}
int ans=;
for(i=;i<n;i++)
for(j=i+;j<n;j++)
ans=max(gcd(a[i],a[j]),ans);
cout<<ans<<endl;
}
return ;
}

UVA 11827 Maximum GCD的更多相关文章

  1. UVA - 11827 - Maximum GCD,10200 - Prime Time (数学)

    两个暴力题.. 题目传送:11827 Maximum GCD AC代码: #include <map> #include <set> #include <cmath> ...

  2. UVA 11827 Maximum GCD【GCD,stringstream】

    这题没什么好说的,但是输入较特别,为此还WA了一次... 题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge& ...

  3. UVA 11827 Maximum GCD (输入流)

    题目:传送门 题意:求n个数的最大公约数,暴力不会超时,难点在没有个数控制的输入. 题解:用特殊方法输入. #include <iostream> #include <cmath&g ...

  4. 邝斌带你飞之数论专题--Maximum GCD UVA - 11827

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

  5. Maximum GCD(UVA 11827)

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

  6. UVA11827 Maximum GCD

    /* UVA11827 Maximum GCD https://vjudge.net/contest/153365#problem/V 数论 gcd 水题,然而读入比较坑 * */ #include ...

  7. uva 10951 - Polynomial GCD(欧几里得)

    题目链接:uva 10951 - Polynomial GCD 题目大意:给出n和两个多项式,求两个多项式在全部操作均模n的情况下最大公约数是多少. 解题思路:欧几里得算法,就是为多项式这个数据类型重 ...

  8. UVa 10827 - Maximum sum on a torus

    题目大意:UVa 108 - Maximum Sum的加强版,求最大子矩阵和,不过矩阵是可以循环的,矩阵到结尾时可以循环到开头.开始听纠结的,想着难道要分情况讨论吗?!就去网上搜,看到可以通过补全进行 ...

  9. Maximum GCD(fgets读入)

    Maximum GCD https://vjudge.net/contest/288520#problem/V Given the N integers, you have to find the m ...

随机推荐

  1. linux 分区问题

    一.最简单的分区 仅分出根目录(/)和最简单的内存置换空间(swap)即可 以虚拟机的分区(20G)为例: 一般给/分15G来安装linux系统,512M给swap,另外的4G可以留下备用 二.复杂一 ...

  2. 微信电脑版即将到来了 安装QQ浏览器微信版体验吧

    之前说过在手机上微信打字慢,tx最终还是想开了,最近TX邀请测试微信电脑版,想要尝鲜的朋友可以去exp.qq.com申请QQ浏览器微信版体验,不过体验将要结束了,相信正式版很快就要出来了.[微信网页版 ...

  3. IE浏览器版本判断

    <script type="text/javascript"> var browser=navigator.appName var b_version=navigato ...

  4. 信号屏蔽的切换的理解sigsuspend

    #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <unistd.h&g ...

  5. php导入导出cvs文件格式

    1.导入 <?php header("Content-type: text/html; charset=gb2312"); $fname = $_FILES['myfile' ...

  6. 设计模式(15)-Facade Pattern

    http://www.cnblogs.com/zhenyulu/articles/55992.html 一. 门面(Facade)模式 外部与一个子系统的通信必须通过一个统一的门面(Facade)对象 ...

  7. Cocos2d-x 3.0 Json用法 Cocos2d-x xml解析

    Cocos2d-x 3.0 加入了rapidjson库用于json解析.位于external/json下. rapidjson 项目地址:http://code.google.com/p/rapidj ...

  8. Oracle Database 11g Express Edition学习笔记

    修改字符集 使用用户system,通过sqlplus程序连接到Oracle数据库,输入以下命令,查看字符集: SQL> select userenv('language') from dual; ...

  9. php处理数据库数据,每处理一个数据返回客户端显示当前状态的方法。

    php处理大量数据,每处理一个数据返回客户端显示当前状态的方法. 类似于dedecms生成静态页 想法: 客户端发送请求 服务器端接受请求,开始统计所需处理的数据量 将所需处理数据按一定规则排列,发送 ...

  10. 1.6---旋转二维数组,旋转图像像素,旋转矩阵,90度(CC150)

    import java.util.*; public class Transform { public int[][] transformImage(int[][] matrix, int n) { ...