问题链接:POJ1845 Sumdiv。

问题简述:参见上述链接。

问题分析:计算a^b的因子数,首先要对a进行因子分解,然后再进行计算。

程序说明:计算过程中用到了快速模幂函数。

题记:(略)

AC的C++语言程序如下:

/* POJ1845 Sumdiv */#include <iostream>using namespace std;const int MOD = 9901;
const int N = 1000;int fact[N+1], e[N+1], fcount;void setfact(int n)
{fcount = 0;if(n && n % 2 == 0) {fact[fcount] = 2;e[fcount] = 0;while(n && n % 2 == 0) {e[fcount]++;n /= 2;}fcount++;}for(int i=3; i*i <=n; i+=2) {if(n % i == 0) {fact[fcount] = i;e[fcount] = 0;while(n && n % i == 0) {e[fcount]++;n /= i;}fcount++;}}if(n != 1) {fact[fcount] = n;e[fcount] = 1;fcount++;}
}// 快速模幂计算函数
long long powermod(long long a, long long n, int m)
{long long res = 1;while(n) {if(n & 1) {        // n % 2 == 1res *= a;res %= m;}a *= a;a %= m;n >>= 1;}return res;
}//递归二分求 (1 + p + p^2 + p^3 +...+ p^n)%mod
long long sum(long long p, long long n)
{if(n==0)return 1;else if(n % 2)// 奇数:(1 + p + p^2 +...+ p^(n/2)) * (1 + p^(n/2+1))return (sum(p, n / 2) * (1 + powermod(p, n/2+1, MOD))) % MOD;else// 偶数:(1 + p + p^2 +...+ p^(n/2-1)) * (1+p^(n/2+1)) + p^(n/2)return (sum(p, n / 2 - 1) * (1 + powermod(p, n / 2 + 1, MOD)) + powermod(p, n / 2, MOD)) % MOD;
}int main()
{int a, b, ans;while(cin >> a >> b) {setfact(a);ans = 1;for(int i=0; i<fcount; i++)ans = (ans * (sum(fact[i], e[i] * b ) % MOD)) % MOD;cout << ans << endl;}return 0;
}

POJ1845 Sumdiv【快速模幂+素因子分解+等比数列+二分法】相关推荐

  1. 51Nod-1013 3的幂的和【快速模幂+逆元】

    1013 3的幂的和 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 求:3^0 + 3^1 +...+ 3^(N) mod 1000000007 Input 输入 ...

  2. HDU2035 人见人爱A^B【快速模幂】

    人见人爱A^B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  3. 51Nod-1046 A^B Mod C【快速模幂】

    1046 A^B Mod C 基准时间限制:1秒 空间限制:131072KB 分值:0难度:基础题 给出3个正整数A B C,求A^B Mod C. 例如,3 5 8,3^5 Mod 8 = 3. I ...

  4. HDU1163 Eddy's digital Roots(解法二)【快速模幂+九余数定理】

    问题链接:HDU1163 Eddy's digital Roots. 问题简述:参见上述链接. 问题分析:计算n^n的数根,一要快,二要简单.使用快速模幂计算,加上数论中的九余数定理就完美了. 程序说 ...

  5. CodeForces - 1514B AND 0, Sum Big【快速模幂】

    B. AND 0, Sum Big time limit per test2 seconds memory limit per test256 megabytes inputstandard inpu ...

  6. UVA11029 Leading and Trailing【快速模幂+数学】

    Apart from the novice programmers, all others know that you can't exactly represent numbers raised t ...

  7. HDU1420 Prepared for New Acmer【快速模幂】

    Prepared for New Acmer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/O ...

  8. UVA11582 Colossal Fibonacci Numbers!【快速模幂+数列模除】

    The i'th Fibonacci number f(i) is recursively defined in the following way: • f(0) = 0 and f(1) = 1 ...

  9. HDU1163 Eddy's digital Roots(解法二)【快速模幂+九余数定理】(废除!!!)

    本文废除,参见下述链接. 参考链接:HDU1163 Eddy's digital Roots[快速模幂+九余数定理+水题] 问题链接:HDU1163 Eddy's digital Roots. 问题简 ...

最新文章

  1. python nodemcu_NodeMCU简介与快速入门
  2. Wireshark软件的安装,进行数据包的捕获【Wireshark安装使用】
  3. 解决oracle语句中 含数字的字符串按数字排序问题
  4. BZOJ 1051: [HAOI2006]受欢迎的牛
  5. Java 8 Friday:使用Streams API时的10个细微错误
  6. SOTA太难了?试试Dropout
  7. 7-7 旅游规划 (25 分)
  8. 软件nginx 0.8.16
  9. smokeping with tcpping centos 7 环境
  10. 蓝牙音乐之AVRCP常用指令介绍
  11. Oracle Instant Client
  12. k8s的命令行管理工具
  13. sed 批量替换字符串
  14. UINO优锘去ChinaJoy秀数字孪生元宇宙落地应用!
  15. 【异常】解决 Cannot find module ‘./element-ui‘ or its corresponding type declarations.
  16. 计算机网络(七)——互联网上的音频/视频服务 和 无线网络与移动网络
  17. 【Git】error: RPC failed; curl 56 GnuTLS recv error (-9): A TLS packet with unexpected length was rece
  18. font-awesome样式只显示方框
  19. 24C02 EEPROM多个字节连续写入乱码问题解决
  20. PostgreSQL对汉字按拼音排序

热门文章

  1. JQuery使用总结
  2. 巅峰对决 Spring Boot VS .NET 6
  3. [air for ios] 三小时开发一个iOS飞行射击游戏
  4. [开源]quakeIII(雷神之锤3)源码
  5. 在Visual C#中用ListView显示数据记录
  6. linux环境systwm.img解包,[教程] system.img解包打包的方法,方便菜鸟们制作直刷ROM...
  7. Mysql配置项sync_binlog=0
  8. 阿里云搭建CDH集群配置邮箱告警
  9. linux 加速播放软件,VirtualBox 6.1首次推出Linux 5.4支持,加速的视频播放及更多功能...
  10. jfinal 一对一 实体类怎么写_新祥旭考研一对一:考前必知的四大答题技巧