筛选法+求一个整数的分解+快速模幂运算+递归求计算1+p+p^2+````+p^n
POJ 1845 Sumdiv
求A^B的所有约数之和%9901

*/
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
#define MOD 9901
const int MAXN=10000;
int prime[MAXN+1];
void Prime()//筛选法
{
memset(prime,0,sizeof(prime));
for(int i=2;i<=MAXN;i++)
{
if(!prime[i])
prime[++prime[0]]=i;
for(int j=1;j<=prime[0]&&prime[j]<=MAXN/i;j++)
{
prime[prime[j]*i]=1;
if(i%prime[j]==0)
break;
}
}
}
long long factor[100][2];//factor[i][0]存的是因子,factor[i][1]存的是次数
int cnt;//记录不同因子的个数
int getFactors(long long x)
{
cnt=0;
long long tmp=x;
for(int i=1;prime[i]<=tmp/prime[i];i++)
{
factor[cnt][1]=0;
if(tmp%prime[i]==0)
{
factor[cnt][0]=prime[i];
while(tmp%prime[i]==0)
{
factor[cnt][1]++;
tmp/=prime[i];
}
cnt++;
}
}
if(tmp!=1)
{
factor[cnt][0]=tmp;
factor[cnt++][1]=1;
}
return cnt;
}
long long pow_m(long long a,long long n)//快速模幂运算
{
long long res=1;
long long tmp=a%MOD;
while(n)
{
if(n&1){res*=tmp;res%=MOD;}
n>>=1;
tmp*=tmp;
tmp%=MOD;
}
return res;
}
long long sum(long long p,long long n)//计算1+p+p^2+````+p^n
{
if(p==0)
return 0;
if(n==0)
return 1;
if(n&1)//奇数
{
return ((1+pow_m(p,n/2+1))%MOD*sum(p,n/2)%MOD)%MOD;
}
else return ((1+pow_m(p,n/2+1))%MOD*sum(p,n/2-1)+pow_m(p,n/2)%MOD)%MOD;

}
int main()
{
int A,B;
Prime();
while(scanf("%d%d",&A,&B)!=EOF)
{
getFactors(A);
long long ans=1;
for(int i=0;i<cnt;i++)
{
ans*=(sum(factor[i][0],B*factor[i][1])%MOD);
ans%=MOD;
}
printf("%I64d\n",ans);
}
return 0;
}

poj 1845 POJ 1845 Sumdiv 数学模板的更多相关文章

  1. POJ 2406 Power Strings 简单KMP模板 strcmp

    http://poj.org/problem?id=2406 只是模板,但是有趣的是一个strcmp的字符串比较函数,学习到了... https://baike.baidu.com/item/strc ...

  2. POJ 2363 Blocks (ZOJ 1910) 数学

    杨宗纬的歌"这一路走来" 还蛮好听的,这首歌静静的躺在我的音乐盒某个阴暗的角落里,今天随机播放才发现的,哈哈. 数学一直是硬伤...... -------------------- ...

  3. 【BZOJ2242】[SDOI2011] 计算器(数学模板三合一)

    点此看题面 大致题意: 让你完成三种操作:求\(Y^Z\%P\)的值,求满足\(XY\equiv Z(mod\ P)\)的最小非负整数\(X\),求满足\(Y^X\equiv Z(mod\ P)\)的 ...

  4. POJ 1496 POJ 1850 组合计数

    Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8256 Accepted: 3906 Description Tran ...

  5. poj 3264 Balanced Lineup (RMQ算法 模板题)

    RMQ支持操作: Query(L, R):  计算Min{a[L],a[L+1], a[R]}. 预处理时间是O(nlogn), 查询只需 O(1). RMQ问题 用于求给定区间内的最大值/最小值问题 ...

  6. POJ 2359 Questions(约瑟夫环——数学解法)

    题目链接: http://poj.org/problem?id=2359 题意描述: 输入一个字符串 按照下面的规则,如果剩下的最后一个字符是'?',输出"Yes",如果剩下的最后 ...

  7. POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]

    题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...

  8. POJ 1844 Sum【简单数学】

    链接: http://poj.org/problem?id=1844 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=29256#probl ...

  9. [ACM] POJ 3740 Easy Finding (DLX模板题)

    Easy Finding Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16178   Accepted: 4343 Des ...

随机推荐

  1. HFS - 简单的将个人电脑变服务器!

    网络硬盘   HTTP File Server(HFS)是我目前所知道的最简便的P2P文件分享方式,只一个大小为559KB的单文件绿色软件(hfs.exe)就可以在瞬间不经过任何系统设置将一台普通的联 ...

  2. stm32之ADC

    将模拟量转换为数字量的过程称为模式(A/D)转换,完成这一转换的期间成为模数转换器(简称ADC);将数字量转换为模拟量的过程为数模(D/A)转换,完成这一转换的器件称为数模转换器(简称DAC). 模拟 ...

  3. sharePoint常用命令

    New-SPStateServiceDatabase -Name "StateServiceDatabase" | New-SPStateServiceApplication -N ...

  4. 自定义Log4cpp的日志输出格式

    // 1. 实例化一个PatternLayout对象 log4cpp::PatternLayout* pLayout = new log4cpp::PatternLayout(); // 2. 实例化 ...

  5. Beginning MyBatis 3 Part 2 : How to Handle One-to-Many and One-to-One Selects

    One of the latest MyBatis feature is the ability to use Annotations or XML to do One-to-One or One-t ...

  6. 【cocos2d-x】3.0使用cocos-console创建,编,部署游戏

    原文地址:http://fengchenluoyu.duapp.com/272.html cocos2d-x 3.0開始添加了一个cocos-console组件,它位于cocos2d-x 3.0的to ...

  7. Codeforces Round #270 A~D

    Codeforces Round #270 A. Design Tutorial: Learn from Math time limit per test 1 second memory limit ...

  8. linux下编译.so 和.a 可能出现的问题 ?

    1. 静态函数库 这类库的名字一般是libxxx.a:利用静态函数库编译成的文件比较大,因为整个 函数库的所有数据都会被整合进目标代码中,他的优点就显而易见了,即编译后的执行程序不需要外部的函数库支持 ...

  9. 它们偷偷干了啥?教你监督APP的运行

    由于Android系统的开放性,很多APP都会在后台运行各种我们不知道的权限,不仅泄露我们隐私,也给系统本身带来极大安全隐患.而且现在很普遍的是,在安装APP时它总会索取特别多的权限,又是拍照又是地理 ...

  10. 基于visual Studio2013解决面试题之0907大数乘法

     题目