HDU 5207 Greatest Greatest Common Divisor
来源:互联网 发布:计算机编程语言有哪些 编辑:程序博客网 时间:2024/06/05 09:22
题意:求一些数之中两个数的最大公约数
比赛时的做法是:对每一个数求因子 标记每一个因子 如果该因子已经被标记过 则说明存在2个数的公因子是它 与答案取优即可 复杂度O(n根号n)(写的不优美可能会T)
另外一种做法是:对每个数进行标记,枚举某一答案的若干倍,如果当前的答案有2个倍数被标记过,则可以取到 复杂度O(nln(n))
#include<iostream>#include<cstdio>#include<cstring>#include<cctype>#include<cmath>#include<vector>#include<queue>#include<map>#include<algorithm>#include<set>#define scnaf scanf#define cahr char#define bug puts("bugbugbug");using namespace std;typedef long long ll;const int mod=1000000007;const int maxn=1e5+50;const int inf=1e9;const int maxe=200000;int a[maxn],visit[maxn];int main(){ int T_T,test=1; scanf("%d",&T_T); while(T_T--) { int n,ans=0; scnaf("%d",&n); memset(visit,0,sizeof(visit)); for(int i=0;i<n;i++) { scanf("%d",&a[i]); int l=sqrt(a[i]+1); for(int j=1;j<=l&&j<=a[i];j++) if(a[i]%j==0) { if(visit[j]) ans=max(ans,j); visit[j]=1; if(visit[a[i]/j]) ans=max(ans,a[i]/j); visit[a[i]/j]=1; } } printf("Case #%d: %d\n",test++,ans); } return 0;}
0 0
- HDU 5207 Greatest Greatest Common Divisor
- 【瞎搞】 HDU 5207 Greatest Greatest Common Divisor
- Greatest Greatest Common Divisor hdu 5207
- hdu 5207 Greatest Greatest Common Divisor
- hdu 5207 Greatest Greatest Common Divisor
- HDU 5207 Greatest Greatest Common Divisor
- HDU 5207Greatest Greatest Common Divisor
- HDU ACM 5207 Greatest Greatest Common Divisor
- HDU 5207 Greatest Greatest Common Divisor
- HDU 5207 Greatest Greatest Common Divisor
- Greatest Greatest Common Divisor
- Hdu 5207 Greatest Greatest Common Divisor(数论)
- hdu 5207 Greatest Greatest Common Divisor(数论)
- HDU 5207 Greatest Greatest Common Divisor(暴力)
- hdu 5207 Greatest Greatest Common Divisor【筛法】【思维】
- hdu 5210 Greatest Greatest Common Divisor
- Greatest Greatest Common Divisor HD5207
- Greatest common divisor
- 真正的程序员为什么想要创造出伟大的作品
- java学习_网络编程
- Karma+Jasmie做前端项目的单元测试
- +1计算1-n有多个不同的二叉树
- HTML标签----图文详解(二)
- HDU 5207 Greatest Greatest Common Divisor
- (总结)Nginx配置文件nginx.conf中文详解
- poj 2104 K-th Number【主席树】
- 指针做函数参数——高效C语言
- HDU 5469 Antonidas(树分治+字符串哈希)
- 正方教务系统加密密码解密之python代码
- C语言快速入门系列-详解
- CF#321-C - Kefa and Park-DFS
- Codeforces Round #317 (Div. 2) 572A.Arrays