HDU 5207 Greatest Greatest Common Divisor
来源:互联网 发布:linux cp mv 编辑:程序博客网 时间:2024/06/05 04:36
问题描述
在数组a中找出两个数ai,aj(i≠j),使得两者的最大公约数取到最大值。
输入描述
多组测试数据。第一行一个数字T,表示数据组数。对于每组数据,第一行是一个数n,表示数组中元素个数,接下来一行有n个数,a1到an。1≤T≤100,2≤n≤105,1≤ai≤105,n≥104的数据不超过10组。
输出描述
每组数据输出一行Case #x: ans。x表示组数编号,从1开始。ans表示能取到的最大值。
解题思路:纪录每个因子出现的次数,如果一个因子的次数超过2次,就表示这个因子至少是两个数的因子,因为一个数的同一个因子是不会超过两次。
这题得反省一下了,太主观臆断了,for的时候只for到了sqrt(t),忘记了他的对称数了,所以一直WA。。。自己想出的思路,结果自己WA了,别人A了,好心塞
#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>using namespace std;#define maxn 100010int vis[maxn];int main() { int test, n, mark = 1; scanf("%d", &test); while(test--) { scanf("%d", &n); memset(vis,0,sizeof(vis)); int t, Max = 0; for(int i = 0; i < n; i++) { scanf("%d", &t); Max = max(Max, t); int lim = (int) sqrt((double)t); for(int j = 1; j <= lim; j++) if(t % j == 0) { vis[j]++; vis[t / j]++; } if(lim * lim == t) vis[t]--; } printf("Case #%d: ", mark++); for(int i = Max; i >= 1; i--) if(vis[i] >= 2) { printf("%d\n",i); break; } } 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
- 自己动手写C语言库函数(3) strstr
- 链表的实现
- RSA加密解密原理
- poj1696Space Ant
- UVA 10361 解题报告
- HDU 5207 Greatest Greatest Common Divisor
- 图书管理系统的操作员信息管理界面及其功能设计
- 【面试题】判断字符串是否匹配一定的模式
- 通过客户端编程方式调用webService
- [笔记]hadoop2.4.1分布式集群搭建入门/ha/zookeeper
- NYOJ 427 & HDU 1005 Number Sequence(找循环节)
- 黑马程序员_日记59_TreeMap自定义对象练习
- CXF中Web服务请求处理流程
- 第46课时,实践3,小学生算术测试程序加强版