UVA11827 Maximum GCD
/*
UVA11827 Maximum GCD
https://vjudge.net/contest/153365#problem/V
数论 gcd
水题,然而读入比较坑
*
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
//#define test
using namespace std;
const int Nmax=; long long gcd(long long a,long long b)
{
if(b==0LL)
return a;
return gcd(b,a%b);
}
long long num[Nmax]; int read(long long &a)
{
long long ans=0LL;
char c=getchar();
while(c==' ')
c=getchar();
int flag=;
while(c>='' && c<='')
{
flag=;
ans=ans*10LL+c-'';
c=getchar();
}
if(flag)
{
a=1LL;
return ;
}
a=ans;
if(c=='\n')
{
//a=1LL;
return ;
}
return ;
} int main()
{
#ifdef test
freopen("uva.in","r",stdin);
#endif
int n;
scanf("%d",&n);
getchar();
while(n--)
{
long long mmax=-1LL;
int m=;
while(read(num[++m]));
//for(int i=1;i<=m;i++)
//printf("%d ",num[i]);
//printf("\n");
for(int i=;i<=m;i++)
{
for(int j=i+;j<=m;j++)
{
mmax=max(mmax,gcd(num[i],num[j]));
}
}
printf("%lld\n",mmax);
}
return ;
}
UVA11827 Maximum GCD的更多相关文章
- UVA 11827 Maximum GCD
F - Maximum GCD Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Given the ...
- Maximum GCD(fgets读入)
Maximum GCD https://vjudge.net/contest/288520#problem/V Given the N integers, you have to find the m ...
- Maximum GCD (stringstream)题解
Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possiblepa ...
- 邝斌带你飞之数论专题--Maximum GCD UVA - 11827
Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possible p ...
- UVA - 11827 - Maximum GCD,10200 - Prime Time (数学)
两个暴力题.. 题目传送:11827 Maximum GCD AC代码: #include <map> #include <set> #include <cmath> ...
- Maximum GCD(UVA 11827)
Problem:Given the N integers, you have to find the maximum GCD (greatest common divisor) of every po ...
- Codeforces Round #651 (Div. 2) A Maximum GCD、B GCD Compression、C Number Game、D Odd-Even Subsequence
A. Maximum GCD 题意: t组输入,然后输入一个n,让你在区间[1,n]之间找出来两个不相等的数a,b.求出来gcd(a,b)(也就是a,b最大公约数).让你求出来最大的gcd(a,b)是 ...
- UVA 11827 Maximum GCD (输入流)
题目:传送门 题意:求n个数的最大公约数,暴力不会超时,难点在没有个数控制的输入. 题解:用特殊方法输入. #include <iostream> #include <cmath&g ...
- UVA 11827 Maximum GCD【GCD,stringstream】
这题没什么好说的,但是输入较特别,为此还WA了一次... 题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge& ...
随机推荐
- <图形图像,动画,多媒体> 读书笔记 --- 录制与编辑视频
使用UIImagePickerController 进行录制 #import "ViewController.h" #import <MobileCoreServices/M ...
- golang自己定义数据类型查询与插入postgresql中point数据
golang自己定义数据类型查询与插入postgresql中point数据 详细代码例如以下: package main import ( "bytes" "databa ...
- c++迭代器失效问题
参考两篇文章:https://blog.csdn.net/skyroben/article/details/70877008 https://lichanghao.github.io/2016/08/ ...
- udev详解【转】
本文转载自:http://blog.csdn.net/skyflying2012/article/details/9359185 如果你使用Linux比较长时间了,那你就知道,在对待设备文件这块,Li ...
- base64对文件进行加密
将原文件读取为字节数组,然后用base64加密,得到加密的字符串 https://stackoverflow.com/questions/475421/base64-encode-a-pdf-in-c ...
- hdoj-1004-Let the Balloon Rise(水题)
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- package-org.springframework.ui-interface:Model.class
ylbtech-package-org.springframework.ui-interface:Model.class 1.返回顶部 1. /* * Copyright 2002-2012 the ...
- php获取前天的昨天的日期
在PHP里得到前天和昨天的日期的代码前天去面试的时候也是这样,不过我当时记不起来了.就记得MYSQL里面的date_sub(now(),'interval 1 day');date('Y/m/d h: ...
- Linux Shell Scripting Cookbook 读书笔记 2
cat,script,find, xargs, tr, tmp文件,字符串截取,批量文件重命名,固定大小文件,自动化交互 1. cat的用法 压缩连续的空白行 cat -s file 也可以用tr,将 ...
- 对JVM还有什么不懂的?一文章带你深入浅出JVM!
本文跟大家聊聊JVM的内部结构,从组件中的多线程处理,JVM系统线程,局部变量数组等方面进行解析 JVM JVM = 类加载器(classloader) + 执行引擎(execution engine ...