当前位置:网站首页>数论求a^b(a,b为1e12级别)的因子之和
数论求a^b(a,b为1e12级别)的因子之和
2022-04-23 07:21:00 【2020100XWH】
1.首先考虑将a质因子分解,筛出1e6内的a的质因子及幂次,若a还有质因子(未被筛成1的话)则有一个大于1e6的大质因子(至多一个)(补上即找到所有质因子)
2.将b放入幂指数
3.考虑一个生成函数
a^b的因子之和=(p1^0+p1^1.....+p1^k1)(p2^0+.....+p2^k2).....(pm^0+...pm^km)
这个生成函数的每一项都是一个不同的因子(此处p为a的质因子)
4.最后就是处理一系列等比数列的和,方法一是等比求和,但由于mod过小 有可能出现q为1的情况 ,此时要回到求和(个别),其余正常求
方法二是直接递归log求等比数列连续和(模版如下)
(注意qmul防乘法溢出(大于1e9容易))
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx=1000006;
const int mod=9901;
int pri[maxx];
bool ispri[maxx];
int cnt;
long long cc[maxx];
void prime()
{
cnt=1;
memset(ispri,1,sizeof(ispri));
ispri[0]=ispri[1]=0;
for(int i=2;i<=maxx;++i)
{
if(ispri[i])
pri[cnt++]=i;
for(int j=1;j<cnt&&pri[j]*i<maxx;++j)
{
ispri[pri[j]*i]=0;
if(i%pri[j]==0)
break;
}
}
}
ll qmul(ll a,ll b)
{
ll ans=0;
while(b)
{
if(b&1)
ans=(ans+a)%mod;
a=(a+a)%mod;
b>>=1;
}
return ans;
}
ll qpow(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1)
ans=qmul(ans,a);
a=qmul(a,a);
b>>=1;
}
return ans;
}
ll m(ll x)
{
return qpow(x,mod-2);
}
ll work(ll a,ll b)
{
if(b==0ll) return 1ll;
if(b==1ll) return (1+a)%mod;
if(b%2==0) return ((1ll+qpow(a,b/2))%mod*work(a,(b-1)/2)%mod*a%mod+1ll)%mod;
return (1ll+qpow(a,(b+1ll)/2))%mod*work(a,b/2)%mod;
}
int main ()
{
freopen("spring.in","r",stdin);
freopen("spring.out","w",stdout);
ll a,b;
cin>>a>>b;
prime();
--cnt;
long long k;
int maxx;
for(int i=1;i<=cnt;++i)
{
if(a%pri[i]==0)
{
maxx=i;
cc[i]=1;
a/=pri[i];
while(1)
{
if(a%pri[i]==0)
{
cc[i]++;
a/=pri[i];
}
else break;
}
}
cc[i]*=b;
}
ll ans=1;
for(int i=1;i<=maxx;++i)
{
if(cc[i])
ans=(ans*work(pri[i],cc[i]))%mod;
}
if(a>1)
ans=(ans*work(a,b))%mod;
cout<<ans;
return 0;
}
版权声明
本文为[2020100XWH]所创,转载请带上原文链接,感谢
https://blog.csdn.net/xuwnehao/article/details/124355594
边栏推荐
- ansible自动化运维详解(一)ansible的安装部署、参数使用、清单管理、配置文件参数及用户级ansible操作环境构建
- Depth of binary tree
- synchronized 实现原理
- Draw a circle quickly in MATLAB (the one that can be drawn directly given the coordinates and radius of the center of the circle)
- 5.6 综合案例-RTU-
- mysql查询字符串类型的字段使用数字类型查询时问题
- There are some problems when using numeric type to query string type fields in MySQL
- C language learning record -- use and analysis of string function (2)
- PHP generates short links: convert numbers to letters and letters to numbers
- Somme numérique de la chaîne de calcul pour un problème simple de leetcode
猜你喜欢

怎么读书读论文

【解释】get ORA-12838: cannot read/modify an object after modifying it in parallel

Ubuntu安装Mysql并查询平均成绩

Distributed service governance Nacos

为什么会存在1px问题?怎么解决?

Qt读写XML文件

The third divisor of leetcode simple question

Community group purchase applet source code + interface DIY + nearby leader + supplier + group collage + recipe + second kill + pre-sale + distribution + live broadcast

Kubernetes in browser and IDE | interactive learning platform killercoda

通过实现参数解析器HandlerMethodArgumentResolver接口来自定义注解
随机推荐
Online app resource download website source code
Qt读写XML文件
5.6 comprehensive case - RTU-
[go] common concurrency model [generic version]
[untitled]
thinkphp6+jwt 实现登录验证
396. Rotate Function
ansible自动化运维详解(一)ansible的安装部署、参数使用、清单管理、配置文件参数及用户级ansible操作环境构建
AAAI 2022 recruit speakers!!
C语言学习记录——삼십팔 字符串函数使用和剖析(2)
2022.4.11-4.17 AI industry weekly (issue 93): the dilemma of AI industry
Weekly leetcode - 06 array topics 7 ~ 739 ~ 50 ~ offer 62 ~ 26 ~ 189 ~ 9
A simple theme of Typecho with beautiful appearance_ Scarfskin source code download
室内定位技术对比
Brief description of CPU
5.6 综合案例-RTU-
PyQt5开发之QTableWidget表头自定义与美化(附源代码下载)
【Appium】测试时遇到手机内嵌H5页面的切换问题
使用JWT生成与解析Token
nn.Module类的讲解