题目大意:
给定一组数,取两个数,使得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的更多相关文章

  1. hdu 5207 Greatest Greatest Common Divisor 数学

    Greatest Greatest Common Divisor Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/ ...

  2. HDU 5207 Greatest Greatest Common Divisor

    题目链接: hdu:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=153598 bc(中文):http://bestco ...

  3. hdu 5207 BestCoder Round #38 ($) Greatest Greatest Common Divisor

    #include<stdio.h> #include<string.h> #include<math.h> ]; ]; int main() { int sb; s ...

  4. HDU 4286 Data Handler 双向链表/Splay

    Data Handler Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. cf731E

    题意:一个游戏,由n张贴纸组成.贴纸排成一排,并且纸条上标有数字,玩家轮流揭下m张从左到右连续的纸条(m大等2),揭下后玩家得分累加这些纸条的sum,并且在剩下纸条最左边贴上新的纸条,数值为揭下纸条的 ...

  2. static详解

    static关键字用来修饰属性.方法,称这些属性.方法为静态属性.静态方法. static关键字声明一个属性或方法是和类相关的,而不是和类的某个特定的实例相关,因此,这类属性或方法也称为“类属性”或“ ...

  3. fetch VS AJAX

    fetch('https://mywebsite.com/endpoint/', { method: 'POST', headers: { 'Accept': 'application/json', ...

  4. Java基础毕向东day04

    1. 数组 2.选择排序.冒泡排序.折半查找.

  5. oracle视图如何使用

    1.视图的概述 视图其实就是一条查询sql语句,用于显示一个或多个表或其他视图中的相关数据.视图将一个查询的结果作为一个表来使用,因此视图可以被看作是存储的查询或一个虚拟表.视图来源于表,所有对视图数 ...

  6. Logger.getLogger()和 LogFactory.getLog()

    Logger.getLogger()和LogFactory.getLog()的区别:    1.Logger.getLogger()是使用log4j的方式记录日志:2.LogFactory.getLo ...

  7. http请求利器: 今天配置出了RESTClient,用MAVEN构建了UI运行包

  8. 黑马程序员——【Java基础】——多线程

    ---------- android培训.java培训.期待与您交流! ---------- 一.概述 (一)进程 正在执行中的程序,每一个进程执行都有一个执行顺序.该顺序是一个执行路径,或者叫一个控 ...

  9. DB other operation

    A prepared statement is a feature used to execute the same/similar SQL statement repeatedlly with hi ...

  10. JS-OC通信之Cordova简介

    Cordova 是一个可以让 JS 与原生代码(包括 Android 的 java,iOS 的 Objective-C 等)互相通信的一个库,并且提供了一系列的插件类,比如 JS 直接操作本地数据库的 ...