#Pollard-Rho,高精度#洛谷 3499 [POI2010]NAJ-Divine Divisor
题目
给定\(m\)个数\(a_i\),令\(n=\prod_{i=1}^m a_i\),
问有多少个大于1的正整数\(d\)满足\(d^{\max k}|n\)
并输出\(\max k\),\(m\leq 600,a_i\leq 10^{18}\)
分析
将\(a_i\)质因数分解,\(n\)的指数累加,那么就可以使\(n\)质因数分解,
若有\(p\)个质数使得\(p^{\max k}|n\),\(d\)的个数为\(2^p-1\),
由于\(p\leq 600\),所以要高精度乘法
代码
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <map>
#define rr register
using namespace std;
const double ha=pow(11.0,19/17.0);
const int prime[8]={2,61,97,7,13,17,23,29},MOD=1000000000;
typedef long long lll; lll x,n,tot,mx,ans,p[41],dig[211];
map<lll,int>uk; map<lll,int>::iterator it;
inline lll iut(){
rr lll ans=0; rr char c=getchar();
while (!isdigit(c)) c=getchar();
while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
return ans;
}
inline lll mo(lll a,lll b,lll mod){return a+b>=mod?a+b-mod:a+b;}
inline lll mul(lll a,lll b,lll mod){return (a*b-(lll)((long double)a/mod*b)*mod+mod)%mod;}
inline lll gcd(lll a,lll b){return b?gcd(b,a%b):a;}
inline lll ksm(lll x,lll y,lll mod){
rr lll ans=1;
for (;y;y>>=1,x=mul(x,x,mod))
if (y&1) ans=mul(ans,x,mod);
return ans;
}
inline bool mr(lll n){
if (n==1) return 0;
for (rr int i=0;i<8;++i)
if (n==prime[i]) return 1;
for (rr int i=0;i<8;++i)
if (n%prime[i]==0) return 0;
rr lll m=n-1; rr int cnt=0;
while (!(m&1)) m>>=1,++cnt;
for (rr int i=0;i<8&&prime[i]<n;++i){
rr lll now=ksm(prime[i],m,n),ls=now;
for (rr int j=1;j<=cnt;++j){
now=mul(now,now,n);
if (now==1&&ls!=1&&ls!=n-1) return 0;
ls=now;
}
if (now!=1) return 0;
}
return 1;
}
inline lll rho(lll n,lll h){
if (!(n&1)) return 2;
if (!(n%3)) return 3;
rr lll x1=(rand()+1)%n,x2=x1,p=1;
for (rr int k=2;;k<<=1,x2=x1,p=1){
for (rr int i=1;i<=k;++i){
x1=mo(mul(x1,x1,n),h,n);
p=mul(p,x1>x2?x1-x2:x2-x1,n);
if (!(i&127)){
rr lll d=gcd(p,n);
if (d>1) return d;
}
}
rr lll d=gcd(p,n);
if (d>1) return d;
}
}
inline void dfs(lll n){
if (n==1) return;
if (mr(n)){
p[++tot]=n;
return;
}
rr lll t=n;
while (t==n) t=rho(n,rand()%(n-1)+1);
while (!(n%t)) n/=t;
dfs(t),dfs(n);
}
inline void cheng(int t){
rr lll s=0,g=0;
for (rr int i=1;i<=dig[0];++i)
s=dig[i]*t+g,g=s/MOD,dig[i]=s%MOD;
if (g) dig[++dig[0]]=g;
}
signed main(){
n=iut(),srand((unsigned)((lll)(new char)*ha));
for (rr int i=1;i<=n;++i){
tot=0,dfs(x=iut());
for (rr int i=1;i<=tot;++i){
rr int c=0;
while (x%p[i]==0) x/=p[i],++c;
uk[p[i]]+=c;
}
}
for (it=uk.begin();it!=uk.end();++it)
if (mx<it->second) mx=it->second,ans=1;
else if (mx==it->second) ++ans;
dig[dig[0]=1]=1;
for (rr int i=1;i<=ans/25;++i) cheng(33554432);
if (ans%25) cheng(1<<(ans%25));
--dig[1],printf("%lld\n",mx);
printf("%lld",dig[dig[0]]);
for (rr int i=dig[0]-1;i;--i) printf("%09lld",dig[i]);
return 0;
}
#Pollard-Rho,高精度#洛谷 3499 [POI2010]NAJ-Divine Divisor的更多相关文章
- 洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速$dp\&Floyd$)
洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速\(dp\&Floyd\)) 标签:题解 阅读体验:https://zybuluo.com/Junl ...
- [洛谷P3501] [POI2010]ANT-Antisymmetry
洛谷题目链接:[POI2010]ANT-Antisymmetry 题目描述 Byteasar studies certain strings of zeroes and ones. Let be su ...
- 洛谷 P3496 [POI2010]GIL-Guilds
P3496 [POI2010]GIL-Guilds 题目描述 King Byteasar faces a serious matter. Two competing trade organisatio ...
- 洛谷 P3507 [POI2010]GRA-The Minima Game
P3507 [POI2010]GRA-The Minima Game 题目描述 Alice and Bob learned the minima game, which they like very ...
- 洛谷 P3505 [POI2010]TEL-Teleportation
P3505 [POI2010]TEL-Teleportation 题目描述 King Byteasar is the ruler of the whole solar system that cont ...
- 【字符串】【hash】【倍增】洛谷 P3502 [POI2010]CHO-Hamsters 题解
这是一道字符串建模+图论的问题. 题目描述 Byteasar breeds hamsters. Each hamster has a unique name, consisting of lo ...
- 洛谷P3507 [POI2010]GRA-The Minima Game
题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...
- [洛谷P3509][POI2010]ZAB-Frog
题目大意:有$n$个点,每个点有一个距离(从小到大给出),从第$i$个点跳一次,会跳到距离第$i$个点第$k$远的点上(若有两个点都是第$k$远,就跳到编号小的上).问对于从每个点开始跳,跳$m$次, ...
- [洛谷P3512 [POI2010]PIL-Pilots]
题目链接: 传送门走这里 题目分析: 感觉不是很难啊--不像是蓝题(AC量也不像)恶意评分? 少打了一个+1调了半天,就这样居然还能过60pts?我思路和题解第一篇高度重合是什么鬼啊,太过分了吧本来还 ...
- 【BZOJ2082】【POI2010】Divine divisor 假的pollard-rho
题目大意:给你$m$个数$a_i$,定义$n=\Pi_{i=1}^{m}a_i$.将$n$分解质因数为$\Pi p_i^{k_i} $,$p_i$是质数.请输出$2^{max(k_i)}-1$,以及存 ...
随机推荐
- 一个有意思的问题:Kafka的消费Offset会溢出吗
最近在项目上接入公司APP产品的用户点击日志数据时,发现消费者组的Offset值非常大,才一天的时间,已提交的Offset值就有千亿级别了. 于是不禁想了一个问题:假设一个Topic就只有一个Part ...
- APScheduler可能遇到的问题
uWsgi使用多进程模式启动Django项目,因此我们会有多个进程去执行这个定时任务,导致定时任务被重复执行.解决这个问题的方法,我们直接就会想到采用加锁的方式.第一个拿到锁的进程,执行定时任务,其余 ...
- ASP.NET 上传文件导入Excel
前言 本文对应的场景是导入Excel数据,Excel对应的字段都配置在xml文件中.截图如下: 代码实战 工具类 实体类:XMLReadModel.cs public class XMLReadMod ...
- 详解 nebula 2.0 性能测试和 nebula-importer 数据导入调优
这是由社区用户--繁凡撰写的一篇他的实践分享,主要讲解如何进行 Nebula 性能测试以及数据导入部分的性能调优.下文中出现的"我"代指用户繁凡. 0. 概要 之前在做 Nebul ...
- win上vscode配置ffmpeg
参考博客https://blog.csdn.net/leixiaohua1020/article/details/38868499 https://blog.csdn.net/weixin_37515 ...
- 【苹果】SpringBoot监听Iphone15邮件提醒,Selenium+Python自动化抢购脚本
前言 缘由 Iphone15来了,两年之约你还记得吗? 遂整合之前iphone13及iphone14的相关抢购代码,完成一个SpringBoot监听Iphone15有货邮件提醒+python自动化脚本 ...
- C++ //案列-员工分组 ( 容器存放,查找,打印,统计,宏定义 ,随机)
//案列-员工分组//描述:公司招聘10个员工(ABCDEFGHIJ),10名指派员工进入公司,需要指派那个员工在那个部门工作//员工信息有:姓名 工资组成: 部门分为:策划 美术 研发//随机给10 ...
- WPF开源的一款免费、开箱即用的翻译、OCR工具
前言 今天大姚给大家分享一款由WPF开源的.免费的(MIT License).即开即用.即用即走的翻译.OCR工具:STranslate. WPF介绍 WPF 是一个强大的桌面应用程序框架,用于构建具 ...
- Python文件操作系统
[一]文件操作基本流程 # 1. 打开文件,由应用程序向操作系统发起系统调用open(...),操作系统打开该文件,对应一块硬盘空间,并返回一个文件对象赋值给一个变量f f=open('a.txt', ...
- 教你一招,解决Github图片不显示问题(2021.1.20测试可用)
本文提供的是windows系统解决方法,linux系统和mac系统可以参考原理,修改DNS的ip地址为阿里云或者是修改hosts文件 问题 可能有些朋友和我遇到同样的问题,逛Github的时候会发现, ...