hdu5207Greatest Greatest Common Divisor+枚举
来源:互联网 发布:永久域名 编辑:程序博客网 时间:2024/06/01 08:17
Description
Pick two numbers from a sequence to maximize the value of their greatest common divisor.
Input
Multiple test cases. In the first line there is an integer , indicating the number of test cases. For each test cases, the first line contains an integer , the size of the sequence. Next line contains numbers, from to . . The case for is no more than .
Output
For each test case, output one line. The output format is Case # : , is the case number, starting from , is the maximum value of greatest common divisor.
Sample Input
2
4
1 2 3 4
3
3 6 9
Sample Output
Case #1: 2
Case #2: 3
给一堆数,找出任意两个数之间的最大的公约数。
枚举每一个数的约数,记录个数。这样总的约数个数>=2就是某两个数的约数情况,直接从最大的饭后遍历,找到第一个>2的即可。
#include<bits/stdc++.h>using namespace std;int ans[100005];int main(){ int t; scanf("%d",&t); for(int cas=1;cas<=t;cas++){ int n; scanf("%d",&n); memset(ans,0,sizeof(ans)); for(int i=1;i<=n;i++){ int x; scanf("%d",&x); for(int j=1;j*j<=x;j++){ if(x%j==0){ ans[j]++; if(x/j!=j) ans[x/j]++; } } } for(int i=100005;i>=1;i--){ if(ans[i]>=2){ printf("Case #%d: %d\n",cas,i); break; } } } return 0;}
- hdu5207Greatest Greatest Common Divisor+枚举
- Greatest Greatest Common Divisor
- HDOJ 5207 Greatest Greatest Common Divisor 暴力枚举
- sgu 499. Greatest Greatest Common Divisor(枚举因子)
- Greatest Greatest Common Divisor HD5207
- Greatest common divisor
- The Greatest Common Divisor
- GCD (Greatest Common Divisor)
- Solving Greatest Common Divisor
- the greatest common divisor
- 最大公约数Greatest Common Divisor
- 最大公约数(greatest common divisor)算法
- 最大公约数(Greatest Common Divisor)
- GCD Algorithm(Greatest Common Divisor)
- SGU 499:Greatest Greatest Common Divisor
- HDU 5207 Greatest Greatest Common Divisor
- 【瞎搞】 HDU 5207 Greatest Greatest Common Divisor
- Greatest Greatest Common Divisor hdu 5207
- ab压力测试
- 基于CentOS的nfs文件系统搭建
- 大数据系列修炼-Scala课程37
- HDU 5901 Count primes【数论】
- My97 WdatePicker 属性
- hdu5207Greatest Greatest Common Divisor+枚举
- 大数据系列修炼-Scala课程38
- css 中display的inherit
- 第4周项目6--多项式求和
- 前端基础之CSS(1)
- BGRABitmap图像操作12:文本操作功能
- VMware虚拟机安装CentOS 6.8 (图解)
- 应用系统之间数据传递的几种方式
- POJ_1182_食物链