题目大意:
给定一组数,取两个数,使得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. 使用SoundPool播放音效

    针对应用程序经常需要播放密集.短促的音效,因为MediaPlayer存在如下缺点: 1.资源占用量较高.延迟时间较长. 2.不支持多个音效同时播放. SoundPool使用音效池的概念来管理多个短促的 ...

  2. 百度360争推1TB永久网盘

    导读:百度云.360云盘的互掐则将云盘空间战拉升到史无前例的高度——无论是国内还是国外,还没有哪家公司有过这样的手笔.      这几天百度热热闹闹开大会,会场外“小伙伴们”也不甘寂寞.       ...

  3. 关于Android的onResume的2点体会(程序切换之后恢复状态)

    Android有点儿差劲:按home键之后,立即长按home键选择程序切换回来,居然activity就跑回初始状态去了. 我的程序里面有2个webview,2个按钮,我做到把他们都恢复了. 1 web ...

  4. POJ 3274 Gold Balanced Lineup 哈希,查重 难度:3

    Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been able to narrow ...

  5. 从python中copy与deepcopy的区别看python引用

    讨论copy与deepcopy的区别这个问题要先搞清楚python中的引用.python的内存管理. python中的一切事物皆为对象,并且规定参数的传递都是对象的引用.可能这样说听起来比较难懂,对比 ...

  6. ActiveX 技术疑点 一

    1.编写基于MFC Activex 使用 静态库 .lib , MFC 的使用 在静态库中使用MFC . 生成ocx 文件 注册失败.提示: ***还是一个可执行文件,没有为这个文件类型注册的注册帮助 ...

  7. C++-前缀和后缀

    1,c++规定后缀形式的++操作符有一个int行的参数,被调用时,编译器自动加一个0作为参数给他 2,前缀返回一个reference,后缀返回一个const对象 /////////////////// ...

  8. 【海量视频】2013年上半年BPM厂商'K2'市场活动资料集锦

    3月01日         中广核K2 &SAP流程解决方案分享 活动报道:http://www.k2software.cn/k2events_content/items/k2-sap-346 ...

  9. 读者写者问题继 读写锁SRWLock

    在<秒杀多线程第十一篇读者写者问题>文章中我们使用事件和一个记录读者个数的变量来解决读者写者问题.问题虽然得到了解决,但代码有点复杂.本篇将介绍一种新方法--读写锁SRWLock来解决这一 ...

  10. Fragment 切换问题

    public void switchContent(Fragment fragment) { if(mContent != fragment) { mContent = fragment; mFrag ...