#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$,以及存 ...
随机推荐
- SpringBoot事务注解@Transactional 事物回滚、手动回滚事物
处理springboot 下提交事务异常,数据库没有回滚的问题. spring的文档中说道,spring声明式事务管理默认对非检查型异常和运行时异常进行事务回滚,而对检查型异常则不进行回滚操作. 什么 ...
- 类型注解Callable
from collections.abc import Callable """ Callable[[ParamType1, ParamType2], ReturnTyp ...
- Android底层渲染原理
Overview多年前Android的UI流畅性差的问题一直饱受诟病,Google为了解决这个问题开发了Project Butter项目,也就是黄油计划,期望彻底改善Android系统的流畅性.这是A ...
- 【Azure 事件中心】开启 Apache Flink 制造者 Producer 示例代码中的日志输出 (连接 Azure Event Hub Kafka 终结点)
问题描述 Azure Event Hub 在标准版以上就默认启用的Kafka终结点,所以可以通过Apache Kafka协议连接到Event Hub进行消息的生产和消费.通过示例代码下载到本地运行后, ...
- 使用 RKE 方式搭建 K8s 集群并部署 NebulaGraph
本文由社区用户 Albert 贡献,首发于 NebulaGraph 论坛,旨在提供多一种的部署方式使用 NebulaGraph. 在本文,我将会详细地记录下我用 K8s 部署分布式图数据库 Nebul ...
- C++基本知识梳理
一.命名空间 概念:命名空间是新定义的一个作用域,里面可以放函数,变量,定义类等,主要用来防止命名冲突. 实现:namespace关键字 命名空间名字{ 命名空间成员 } 注意点: 1.命名空间可以嵌 ...
- Java instanceof 全小写 关键字使用
1 package com.bytezreo.duotai2; 2 3 import java.sql.Date; 4 5 /** 6 * 7 * @Description 面向对象的特征三 ---- ...
- C++ //set/multiset 容器 //set不可以插入重复的数字 multiset可以插入重复的数字 //ste容器构造和赋值 //set大小和交换 //set 插入和删除 //set查找和统计 //set 和 multiset 区别 //pair 对组创建 //set存放自定义数据类型 //set内置数据 进行排序
1 //set/multiset 容器 //set不可以插入重复的数字 multiset可以插入重复的数字 2 //ste容器构造和赋值 //set大小和交换 //set 插入和删除 3 //set查 ...
- 【数据结构】哈夫曼树与哈夫曼编码(Huffman Encoding)
一.背景 编码是信息处理的基础(重新表示信息). 普通的编码是等长编码,例如7位的ASCIL编码,对出现频率不同的字符都使用相同的编码长度.但其在传输和存储等情况下编码效率不高. 可使用不等长编码,来 ...
- 移远4G数传模块EC800M开发总结之基本备忘
一 前记 1 EC800M模块是移远推出的小尺寸低功耗针对可穿戴市场的数传产品.笔者在几个产品上使用过程中,遇到了一些问题. 这里做个备忘吧. 二 梳理 1 工具,这个串口的默认波特率为115200. ...