枚举因子·SGU - 499 ·Greatest Greatest Common Divisor

该博客介绍了如何解决寻找一组数中任意两个数的最大GCD问题。通过避免全排列枚举,转而枚举因子以降低复杂度到O(nlogn),并提供了实现此算法的AC代码。
摘要由CSDN通过智能技术生成

题目大意:

给定n个数,求任意两个数的GCD,有很多对,问最大值。

解题思路:

数据量太大不能枚举,我们可以选择枚举因子,这感觉就像这种题的套路,只要枚举的这个因子是某两个或以上的数的公因子,就记录,记录到最后就是最大值,这样的复杂度就是O(nlogn);

AC代码:

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <iostream>
#include <algorithm>
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;
//#define   maxd          1010
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define   mc(x, y)     memcpy(x, y, sizeof(x))
#define   ms(x,y)      memset(x,y,sizeof(x))
#define   rep(i,n)      for(int i&
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值