const int maxn=+;

int prime[maxn];
void marktable(int n){
memset(prime,,sizeof(prime));
for(int i=;i<=n;i++){
if(!prime[i]) prime[++prime[]]=i;
for(int j=;j<=prime[]&&prime[j]<=n/i;j++){
prime[prime[j]*i]=;
if(i%prime[j]==) break;
}
}
}
long long factor[][];
int fatCnt;
int getFactors(long long x){
fatCnt=;
long long tmp=x;
for(int i=;prime[i]<=tmp/prime[i];i++){
factor[fatCnt][]=;
if(tmp%prime[i]==){
factor[fatCnt][]=prime[i];
while(tmp%prime[i]==){
factor[fatCnt][]++;
tmp/=prime[i];
}
fatCnt++;
}
}
if(tmp!=) {
factor[fatCnt][]=tmp;
factor[fatCnt++][]=;
}
return fatCnt;
}
int mod,A,B;
template<class T,class T1> T fast_mod(T a,T b,T1 Mod){
a%=mod;
if(b==) return ;
T ans=,base=a;
while(b!=){
if(b&)ans=(ans*base)%Mod;
base=(base*base)%Mod;
b>>=;
}
return ans;
} long long sum(long long p,long long n){
if(p==) return ;
if(n==) return ;
if(n&) return ((+fast_mod(p,n/+,mod))%mod*sum(p,n/)%mod)%mod;
else return ((+fast_mod(p,n/+,mod))%mod*sum(p,n/-)+fast_mod(p,n/,mod)%mod)%mod;
}
long long solve(long long A,long long B){
getFactors(A);
long long ans=;
for(int i=;i<fatCnt;i++){
ans*=sum(factor[i][],B*factor[i][])%mod;
ans%=mod;
}
return ans;
}

求a^b的约数对mod取模的更多相关文章

  1. 数学:A^B的约数(因子)之和对MOD取模

    POJ1845 首先把A写成唯一分解定理的形式 分解时让A对所有质数从小到大取模就好了 然后就有:A = p1^k1 * p2^k2 * p3^k3 *...* pn^kn 然后有: A^B = p1 ...

  2. hdu 5265 技巧题 O(nlogn)求n个数中两数相加取模的最大值

    pog loves szh II Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  3. a ^ b mod c 取模运算优化反思(老物)

    这是一篇嘲讽我之前的自己采用笨重愚蠢思想去解决问题的日志. RSA 加密与解密涉及到 a ^ b mod c 的问题,如何计算这个值呢? 我会选择 pow(a, b) % c, 事实上在写RSA的时候 ...

  4. mongoDB 高级查询之取模查询$mod

    http://hancang2000.i.sohu.com/blog/view/235140698.htm $mod取模运算   查询age取模10等于0的数据 db.student.find( { ...

  5. hdu 4291 A Short problem(矩阵+取模循环节)

    A Short problem                                                          Time Limit: 2000/1000 MS (J ...

  6. CodeForces 404 Marathon ( 浮点数取模 -- 模拟 )

    B. Marathon time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  7. poj 2065 高斯消元(取模的方程组)

    SETI Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1735   Accepted: 1085 Description ...

  8. ShardingSphere-proxy-5.0.0企业级分库分表、读写分离、负载均衡、雪花算法、取模算法整合(八)

    一.简要说明 以下配置实现了: 1.分库分表 2.每一个分库的读写分离 3.读库负载均衡算法 4.雪花算法,生成唯一id 5.字段取模 二.配置项 # # Licensed to the Apache ...

  9. POJ 1845 求a^b的约数和

    题目大意就是给定a和b,求a^b的约数和 f(n) = sigma(d) [d|n] 这个学过莫比乌斯反演之后很容易看出这是一个积性函数 那么f(a*b) = f(a)*f(b)  (gcd(a,b) ...

随机推荐

  1. vue-cli3点滴

    1.如果你不在构造函数中声明private的变量,那么久会提示错误. 2.

  2. 常用js封装

    //获取url参数 function getUrlParams(name, url) { if (!url) url = location.href; name = name.replace(/[\[ ...

  3. [20200223]关于latch and mutext的优化.txt

    [20200223]关于latch and mutext的优化.txt --//前一段时间一直在测试使用DBMS_SHARED_POOL.MARKHOT标识热对象以及sql语句的优化.--//有别人问 ...

  4. 浅谈centos8与centos7

    距离centos8.0(现在已经更新到8.1了)的发布已经过去几个月了,作为一个刚刚接触过几个月centos的萌新来说,本文想通过实际的操作体验来说对比一下centos8代与7代 首先,centos8 ...

  5. 软链接和硬链接——Linux中的文件共享

    硬链接(Hard Link)和软链接也称为符号链接(Symbolic Link)的目的是为了解决文件的共享使用问题.要阐明其原理,必须先理解Linux的文件存储方式. 索引结点 Linux是一个UNI ...

  6. C#实现把String字符串转化为SQL语句中的In后接的参数

    实现把String字符串转化为In后可用参数代码: public string StringToList(string aa) { string bb1 = "("; if (!s ...

  7. spring security之web应用安全

    一.什么是web应用安全,为了安全我们要做哪些事情? 保护web资源不受侵害(资源:用户信息.用户财产.web数据信息等)对访问者的认证.授权,指定的用户才可以访问资源访问者的信息及操作得到保护(xs ...

  8. IIS在已有站点上->添加应用程序命令

    已有站点:HTTP80 %systemroot%\system32\inetsrv\APPCMD ADD APP /SITE.NAME:"HTTP80" /path:/Redire ...

  9. 【Spring】事务(transactional) - REQUIRES_NEW在JdbcTemplate、Mybatis中的不同表现

    环境 数据库: oracle 11g JAR: org.springframework:spring-jdbc:4.3.8.RELEASE org.mybatis:mybatis:3.4.2 概念 R ...

  10. 战“疫”背后的AI身影丨曼孚科技

    近期新型冠状病毒肺炎的疫情,牵动着全国上下人民的心. 截止2月11日上午10点,全国确诊人数已达42708人,疑似病例21675人. 突发的疫情让部分地区的快速诊疗能力出现了结构性的缺失,为了打赢这场 ...