Maximum GCD(fgets读入)
Maximum GCD
https://vjudge.net/contest/288520#problem/V
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
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 10000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=1e9+;
const double oula=0.57721566490153286060651209;
using namespace std; int n;
char str[];
vector<int>ve; int main(){
scanf("%d%*c",&n);
for(int i=;i<=n;i++){
fgets(str,sizeof(str),stdin);
ve.clear();
int co=;
int len=strlen(str);
for(int j=;j<len;j++){
if(str[j]>=''&&str[j]<=''){
co=co*+str[j]-'';
}
else{
if(co)
ve.pb(co);
co=;
}
}
if(co){
ve.pb(co);
}
int ans=;
for(int i=;i<ve.size();i++){
for(int j=i+;j<ve.size();j++){
ans=max(ans,__gcd(ve[i],ve[j]));
}
}
printf("%d\n",ans);
}
}
Maximum GCD(fgets读入)的更多相关文章
- UVA11827 Maximum GCD
/* UVA11827 Maximum GCD https://vjudge.net/contest/153365#problem/V 数论 gcd 水题,然而读入比较坑 * */ #include ...
- Maximum GCD(UVA 11827)
Problem:Given the N integers, you have to find the maximum GCD (greatest common divisor) of every po ...
- UVA 11827 Maximum GCD
F - Maximum GCD Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Given the ...
- 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> ...
- 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& ...
随机推荐
- [uwsgi: command not found]
问题: pip install uwsgi 之后,运行uwsgi 报错:[uwsgi: command not found] 解决方案:建立软链接 ln -s /usr/local/python3/b ...
- gitlab入门
目录 git下载 注册ssh git客户端及图形化工具tortoisegit下载: git客户端安装: https://git-scm.com/download (git客户端 此种需要命令行执行 ...
- 小麦成长记-<专业盗图好几年>
========================================图片来源朋友圈的朋友~
- git 和 github 学习总结
https://mp.weixin.qq.com/s?src=11×tamp=1543302553&ver=1269&signature=NAX65qusuVVDEl ...
- C#--构造函数的理解
说白了构造函数就是用来初始化类的数据成员{因为C#语言具有类型安全的特质-->不能使用没有初始化的变量)} 在这里引用一下别人的总结,我觉得挺好的: 构造函数是一种特殊的成员函数,它主要用于为对 ...
- bash: export: “path” not a valid identifier [closed]
export SPARK_HOME=/usr/local/spark export PATH=$PATH:$SPARK_HOME/bin bash: export: “path” not a vali ...
- 尚硅谷springboot学习21-web开发-处理静态资源
SpringBoot对静态资源的映射规则 @ConfigurationProperties(prefix = "spring.resources", ignoreUnknownFi ...
- oracle第一天笔记
Oracle体系结构: 数据库 ----> 实例(orcl) ---> 表空间(逻辑单位)(用户) ---> 数据文件(物理单位) 地球 ----> 国家 ...
- [CI]CodeIgniter快速开发指南
---------------------------------------------------------------------------------------------------- ...
- Android DevArt5:如何在Android中创建多线程?
本篇内容: 如何在Android中创建多进程?查看进程的三种方式有哪些? 多进程模式的运行机制?- 演示了多进程出现问题中的两种情况: 静态成员失效 Application多次创建 IPC基础概念介绍 ...