Maximum GCD(UVA 11827)
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)的更多相关文章
- hdu 1695 GCD(莫比乌斯反演)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- 【BZOJ2820】YY的GCD(莫比乌斯反演)
[BZOJ2820]YY的GCD(莫比乌斯反演) 题面 讨厌权限题!!!提供洛谷题面 题解 单次询问\(O(n)\)是做过的一模一样的题目 但是现在很显然不行了, 于是继续推 \[ans=\sum_{ ...
- 【BZOJ2818】Gcd(莫比乌斯反演)
[BZOJ2818]Gcd(莫比乌斯反演) 题面 Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的 数对(x,y)有多少对. Input 一个整数N Ou ...
- 【HDU1695】GCD(莫比乌斯反演)
[HDU1695]GCD(莫比乌斯反演) 题面 题目大意 求\(a<=x<=b,c<=y<=d\) 且\(gcd(x,y)=k\)的无序数对的个数 其中,你可以假定\(a=c= ...
- 求GCD(最大公约数)的两种方式
求GCD(最大公约数)的两种方式 这篇随笔讲解C++语言程序设计与应用中求GCD(最大公约数,下文使用GCD代替)的两种常用方式:更相减损法和辗转相除法,前提要求是具有小学数学的基本素养,知道GCD是 ...
- Codeforces C. Maximum Value(枚举二分)
题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Maximum GCD (stringstream)题解
Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possiblepa ...
- Codeforces 1092F Tree with Maximum Cost(树形DP)
题目链接:Tree with Maximum Cost 题意:给定一棵树,树上每个顶点都有属性值ai,树的边权为1,求$\sum\limits_{i = 1}^{n} dist(i, v) \cdot ...
- P2257 YY的GCD(莫比乌斯反演)
第一次做莫比乌斯反演,推式子真是快乐的很啊(棒读) 前置 若函数\(F(n)\)和\(f(d)\)存在以下关系 \[ F(n)=\sum_{n|d}f(d) \] 则可以推出 \[ f(n)=\sum ...
随机推荐
- opencv实现人脸识别(四) 人脸识别模块
到这一步就是进行人脸识别了. 流程图: 代码: import cv2 def recognize(cam): recognizer = cv2.face.LBPHFaceRecognizer_crea ...
- Python http.server中获取Post的请求报文
今天在自学http.server请求命令, 各个字段都很好理解, 但唯独想打印获取Post请求报文时, 被难住了, 网上找了很多帖子, 官方的文档也刷了几遍, 但没有一个明确的答复. 后来不经意间看到 ...
- BurpSuite 爆破网页后台登陆
由于 Burp Suite是由Java语言编写而成,所以你需要首先安装JAVA的运行环境,而Java自身的跨平台性,使得软件几乎可以在任何平台上使用.Burp Suite不像其他的自动化测试工具,它需 ...
- Attribute自定义特性+Asp.net MVC中的filter详解
转载自:http://blog.csdn.net/wangyy130/article/details/44241957 一.filter简介 在了解自定义特性前,先引入一个概念filter,它是MVC ...
- gdb-example-ncurses
gdb-example-ncurses http://www.brendangregg.com/blog/2016-08-09/gdb-example-ncurses.html 1. The Prob ...
- C#学习资料
http://www.runoob.com/csharp/csharp-delegate.html
- Android opengl 笔记
1. varying vec2 vTextureCoord; 不能用in vec2 ,varying 表示在vs 和 fs中都可见. 2. android 里面 0 和1 都要打小数点 比如0.0 1 ...
- redis 交集、并集、差集
sinter .sunion .sdiff redis 支持 Set集合的数据存储,其中有三个比较特殊的方法: sinter key [key …] 返回一个集合的全部成员,该集合是所有给定集合的交集 ...
- Newtonsoft.Json基本用法
1.将一个 Object 序列化成 JSON: DataSet detail = sqlDB.GetDataSet(string.Format("select * from student ...
- pycharm 报错 ModuleNotFoundError: No module named 'distutils.core'
之气的虚拟机不好使了,重新装了最新版本,安装了ubuntu18.4,然后安装pycharm,但新建项目的时候报错: ModuleNotFoundError: No module named 'dist ...