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. XDU 1160 - 科协的数字游戏I

    Problem 1160 - 科协的数字游戏I Time Limit: 1000MS   Memory Limit: 65536KB   Difficulty: Total Submit: 184   ...

  2. UI第一节—— UILable

    1.首先说说怎么创建UI程序,打开xcode,选择Create  a new Xcode project.看如下截图 2,接下来就蹦出一个和写OC应用差不多的界面,不多解释了 3.我给工程取得名字就叫 ...

  3. Java基础知识总结(绝对经典)

    写代码: 1,明确需求.我要做什么? 2,分析思路.我要怎么做?1,2,3. 3,确定步骤.每一个思路部分用到哪些语句,方法,和对象. 4,代码实现.用具体的java语言代码把思路体现出来. 学习新技 ...

  4. 第六天 做的app不会改变什么

    app包括资源和功能,做完之后没有改变什么

  5. nginx的那些内置变量

    nginx在配置文件nginx.conf中可以使用很多内置变量,配置如下: location /info { add_header 'Content-Type' 'text/html'; echo & ...

  6. Javascript高级程序设计——BOM(浏览器对象模型)

    BOM(浏览器对象模型),它提供了独立于内容而与浏览器窗口进行交互的对象.BOM由一系列相关的对象构成.一.window对象      window对象表示整个浏览器窗口,但不必表示其中包含的内容.W ...

  7. BZOJ4525——[Usaco2016 Jan]Angry Cows

    1.题意:给一堆可以的限制长度的区间...区间的长度是你控制的...但是只有一个长度...求最短长度覆盖所有的点 2.分析:发现可以二分...那二分吧.....然后我们从头向后扫一遍直接判断能否直接覆 ...

  8. tinyhttp源码阅读(注释)

    这里就不细述了,代码很简单. 其实现的功能比较若,可以做一个参考. 因为其通过文件的权限位来判断是否是一个CGI脚本,所以在权限位不对的情况下会判断不正确.例如我将这个目录放置在NTFS分区,所有的文 ...

  9. 7.2---蚂蚁相遇问题(CC150)

    public class Ants { public double antsCollision(int n) { // write code here return (1 - Math.pow(0.5 ...

  10. linux下git安装

    Download for Linux and Unix It is easiest to install Git on Linux using the preferred package manage ...