CF364D Ghd
采用随机的思想,钦定一个一定对答案有贡献的数。把这个数的所有因子拿出来求个贡献就好。(随机 10 次错误的概率就是 1210)。
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<random>
#include<ctime>
using namespace std;
typedef long long LL;
const int N = 1000009;
int n;
LL a[N], Ans, d[N], f[N];
mt19937 rnd(time(0));
void init()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
}
void work()
{
for (int qwq = 1; qwq <= 12; qwq++)
{
LL k = rnd() % n + 1, m = a[k], cnt=0;
for (LL i = 1; i * i <= m; i++)
if(m % i == 0)
{
d[++cnt] = i;
if (i * i != m)
d[++cnt] = m / i;
}
sort(d + 1, d + 1 + cnt);
memset(f, 0, sizeof(f));
for (int i = 1; i <= n; i++)
f[lower_bound(d + 1, d + 1 + cnt, __gcd(a[i], m)) - d]++;
for (int i = cnt; i; i--)
{
int tot = 0;
for (int j = i; j <= cnt; j++)
if(d[j] % d[i] ==0)
tot += f[j];
if(tot >= (n - 1) / 2 + 1)
{
Ans = max(Ans, d[i]);
break;
}
}
}
printf("%lld\n", Ans);
}
int main()
{
init();
work();
return 0;
}
由于博主比较菜,所以有很多东西待学习,大部分文章会持续更新,另外如果有出错或者不周之处,欢迎大家在评论中指出!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步