热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

算法竞赛进阶指南:0x02递推与递归:分治:Sumdiv

题目位置:https:www.acwing.comproblemcontent99借鉴:https:www.acwing.comsolutioncon

题目位置:https://www.acwing.com/problem/content/99/

借鉴:https://www.acwing.com/solution/content/30343/

题目:假设现在有两个自然数 A 和 B,S 是A^{B}的所有约数之和。请你求出 S mod 9901的值是多少。

#include
#include
using namespace std;
typedef long long LL;const int mod=9901;
int a,b;unordered_mapprimes;//快速幂
int poww(int x,int y)
{int ans=1;while(y){if(y&1)ans=(LL)ans*x%mod;y>>=1;x=(LL)x*x%mod;}return ans;
}//分解质因子
void divide(int n)
{for(int i&#61;2; i<&#61;n/i; i&#43;&#43;)if(n%i&#61;&#61;0)while(n%i&#61;&#61;0){n/&#61;i;primes[i]&#43;&#43;;}if(n>1)primes[n]&#43;&#43;;
}//核心
int sum(int p,int c)
{if(c&#61;&#61;0)return 1;//递归结束条件 if(c%2)return (LL)(1&#43; poww(p, (c&#43;1)/2 ) ) * sum(p , (c-1)/2 )%mod;elsereturn ((LL)(1 &#43; poww(p, c/2 ) )*sum(p,c/2-1) &#43; poww(p,c) )%mod;
}int main()
{cin>>a>>b;divide(a);int ans&#61;1;for(auto it:primes){int p&#61;it.first,c&#61;it.second*b;ans&#61;(LL)ans*sum(p,c)%mod;}if(a&#61;&#61;0)ans&#61;0;cout<}

推荐阅读
author-avatar
蔚蓝的希望_674
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有