hdu 5207 Greatest Greatest Common Divisor 数学
Greatest Greatest Common Divisor
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5207
Description
Input
多组测试数据。第一行一个数字T,表示数据组数。对于每组数据,第一行是一个数n,表示数组中元素个数,接下来一行有n个数,a1到an。1≤T≤100,2≤n≤105,1≤ai≤105,n≥104的数据不超过10组。
Output
Sample Input
4
1 2 3 4
3
3 6 9
Sample Output
Case #2: 3
HINT
题意
题解:
直接枚举每个数的因数
然后倒着枚举,看那个数>=2了,就说明那个数就是最大的gcd;
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100101
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/* int buf[10];
inline void write(int i) {
int p = 0;if(i == 0) p++;
else while(i) {buf[p++] = i % 10;i /= 10;}
for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
printf("\n");
}
*/
//**************************************************************************************
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} int a[maxn];
int cnt[maxn];
int main()
{
int t=read();
for(int cas=;cas<=t;cas++)
{
memset(a,,sizeof(a));
memset(cnt,,sizeof(cnt));
int n=read();
for(int i=;i<n;i++)
{
a[i]=read();
cnt[a[i]]++;
}
for(int i=;i<maxn;i++)
for(int j=i+i;j<maxn;j+=i)
cnt[i]+=cnt[j];
int mx=;
for(int i=maxn-;i;i--)
if(cnt[i]>=)
{
mx=i;
break;
}
printf("Case #%d: %d\n",cas,mx);
}
}
hdu 5207 Greatest Greatest Common Divisor 数学的更多相关文章
- CF1025B Weakened Common Divisor 数学
Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input st ...
- CCPC2018 桂林 G "Greatest Common Divisor"(数学)
UPC备战省赛组队训练赛第十七场 with zyd,mxl G: Greatest Common Divisor 题目描述 There is an array of length n, contain ...
- 最大公约数和最小公倍数(Greatest Common Divisor and Least Common Multiple)
定义: 最大公约数(英语:greatest common divisor,gcd).是数学词汇,指能够整除多个整数的最大正整数.而多个整数不能都为零.例如8和12的最大公因数为4. 最小公倍数是数论中 ...
- [UCSD白板题] Greatest Common Divisor
Problem Introduction The greatest common divisor \(GCD(a, b)\) of two non-negative integers \(a\) an ...
- greatest common divisor
One efficient way to compute the GCD of two numbers is to use Euclid's algorithm, which states the f ...
- 845. Greatest Common Divisor
描述 Given two numbers, number a and number b. Find the greatest common divisor of the given two numbe ...
- LeetCode 1071. 字符串的最大公因子(Greatest Common Divisor of Strings) 45
1071. 字符串的最大公因子 1071. Greatest Common Divisor of Strings 题目描述 对于字符串 S 和 T,只有在 S = T + ... + T(T 与自身连 ...
- 【Leetcode_easy】1071. Greatest Common Divisor of Strings
problem 1071. Greatest Common Divisor of Strings solution class Solution { public: string gcdOfStrin ...
- 2018CCPC桂林站G Greatest Common Divisor
题目描述 There is an array of length n, containing only positive numbers.Now you can add all numbers by ...
随机推荐
- 77.PS接收来自PL的按键中断
本篇文章主要介绍外设(PL)产生的中断请求,在PS端进行处理. 在PL端通过按键产生中断,PS接受到之后点亮相应的LED. 本文所使用的开发板是zedboardPC 开发环境版本:Vivado 201 ...
- $FFT$(快速傅里叶变换)
- 概念引入 - 点值表示 对于一个$n - 1$次多项式$A(x)$,可以通过确定$n$个点与值(即$x$和$y$)来表示这唯一的$A(x)$ - 复数 对于一元二次方程 $$x^2 + 1 = 0 ...
- ssh -o 常用选项
ssh -o ConnectTimeout=3 -o ConnectionAttempts=5 -o PasswordAuthentication=no -o StrictHostKeyCheckin ...
- go语言入门(二)
Go 语言变量 Go 语言变量名由字母.数字.下划线组成,其中首个字母不能为数字. 声明变量的一般形式是使用 var 关键字: var identifier type 变量声明 第一种,指定变量类型, ...
- 在flask中返回requests响应
在flask服务端,有时候需要使用requests请求其他url,并将响应返回回去.查阅了flask文档,About Responses,可以直接构造响应结果进行返回. If a tuple is r ...
- HBase原理解析(转)
本文属于转载,原文链接:http://www.aboutyun.com/thread-7199-1-1.html 前提是大家至少了解HBase的基本需求和组件. 从大家最熟悉的客户端发起请求开始讲 ...
- apache Apache winnt_accept: Asynchronous AcceptEx failed 错误的解决
httpd配置文件中添加: AcceptFilter http noneAcceptFilter https none apache优化: http://blog.csdn.net/hytfly/ar ...
- python爬虫实战(六)--------新浪微博(爬取微博帐号所发内容,不爬取历史内容)
相关代码已经修改调试成功----2017-4-13 详情代码请移步我的github:https://github.com/pujinxiao/sina_spider 一.说明 1.目标网址:新浪微博 ...
- Python并发编程-管道
管道的作用- 两个进程间传递消息 from multiprocessing import Pipe, Process def func(conn1,conn2): conn2.close() #子进程 ...
- 简单模仿拉钩网上的“hot_info”
目录 前言 技术 判断进入div的方向 动画 绑定事件 css html 还需改进的地方 前言 突然想起来之前看到拉钩网上的hot_info(不知道该叫什么,但是拉钩网上这个div的class是hot ...