hdu 5207
题目大意:
给定一组数,取两个数,使得gcd最大.
分析:
先nlogn预处理出105所有数的因子,然后用cnt数组计数给定数的因子个数,再找到最大的i,满足cnt[i]>=2,复杂度为nlogn。
学习一下这种思路
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#define INF
#define maxn 100100
using namespace std;
typedef long long LL;
int vist[maxn],cnt[maxn];
int mm;
void solve()
{
for(int i=;i<=mm;i++)
{
for(int j=i;j<=mm;j+=i)
{
if(vist[j])
cnt[i]+=vist[j];
}
}//nlogn 的复杂度
} int main()
{
int t,a[maxn],n;
scanf("%d",&t);
for(int ii=;ii<=t;ii++)
{
scanf("%d",&n);
memset(vist,,sizeof(vist));
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
vist[a[i]]++;
mm=max(mm,a[i]);
}
memset(cnt,,sizeof(cnt));
solve();
cnt[]=;
printf("Case #%d: ",ii);
for(int i=mm;i>=;i--)
if(cnt[i]>=)
{
printf("%d\n",i);
break;
} }
return ;
}
hdu 5207的更多相关文章
- hdu 5207 Greatest Greatest Common Divisor 数学
Greatest Greatest Common Divisor Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/ ...
- HDU 5207 Greatest Greatest Common Divisor
题目链接: hdu:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=153598 bc(中文):http://bestco ...
- hdu 5207 BestCoder Round #38 ($) Greatest Greatest Common Divisor
#include<stdio.h> #include<string.h> #include<math.h> ]; ]; int main() { int sb; s ...
- HDU 4286 Data Handler 双向链表/Splay
Data Handler Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- 第三章 XHTML 表单
1.表单的主要作用在于在网页上提供一个图形用户界面,以采集和提交用户输入的数据. 2.HTML表单元素和属性可以分为两种类型:定义表单整体结构,使浏览器知道如何处理表单数据的元素:创建输入控件的元素. ...
- setsockopt的作用
功能描述: 获取或者设置与某个套接字关联的选 项.选项可能存在于多层协议中,它们总会出现在最上面的套接字层.当操作套接字选项时,选项位于的层和选项的名称必须给出.为了操作套接字层的选项, ...
- c实现的iOS http下载类。支持自己设定http 头(比如cookie等)
也许有人要问为什么要自己用c写? 原因是: 1 我是菜鸟 2 我最最初选择了AsyncSocket,弄了很久,基本上稳定了,但有时候出现了数据不完整,但我又没办法在这个时候识别到并重试:所以不完美,最 ...
- Problem C 链表
Description 某部队进行新兵队列训练,将新兵从一开始按顺序依次编号,并排成一行横队,训练的规则如下:从头开始一至二报数,凡报到二的出列,剩下的向小序号方向靠拢,再从头开始进行一至三报数,凡报 ...
- iOS应用崩溃日志分析
转自raywenderlich 作为一名应用开发者,你是否有过如下经历? 为确保你的应用正确无误,在将其提交到应用商店之前,你必定进行了大量的测试工作.它在你的设备上也运行得很好,但是,上了应 ...
- pyqt5 笔记(二)实现http请求发送
上个图~ index.py 文件 # -*- coding: utf-8 -*- from PyQt5 import QtWidgets,QtCore #从pyqt库导入QtWindget通用窗口类 ...
- UIViewController添加子控制器(addChildViewController)
// // TaskHallViewController.m // yybjproject // // Created by bingjun on 15/10/27. // Copyright ...
- Ch2.Making Reconmmendation in PCI
做<Programing Collective Intelligence>中chapter 2.Making Recommendation的实例,有3个问题花了好长时间: 1. 遇到报错& ...
- linux上安装apache
1 安装aprtar -zxvf apr-1.4.2.tar.gz cd apr-1.4.2.tar.gz ./configure --prefix=/usr/local/aprmake & ...
- php大力力 [009节]php在百度文库的几个基础教程
2015-08-23 php大力力009. php在百度文库的几个基础教程 php大力力 [009节]php在百度文库的几个基础教程 PHP脚本中操作MySQL数据库3-猿代码平台 php基础教程-绝 ...