Sumdiv
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 16466   Accepted: 4101

Description

Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 9901).

Input

The only line contains the two natural numbers A and B, (0 <= A,B <= 50000000)separated by blanks.

Output

The only line of the output will contain S modulo 9901.

Sample Input

2 3

Sample Output

15

Hint

2^3 = 8. 
The natural divisors of 8 are: 1,2,4,8. Their sum is 15. 
15 modulo 9901 is 15 (that should be output). 

要求的是A^B的所有因子的和之后再mod 9901的值。

(1+a1+a1^2+...a1^n1)*(1+a2+a2^2+...a2^n2)*(1+a3+a3^2+...a3^n2)*...(1+am+am^2+...am^nm) mod 9901。

对于每一个(1+a1+a1^2+...a1^n1) mod 9901

等于 (a1^(n1+1)-1)/(a1-1) mod 9901,这里用到逆元的知识:a/b mod c = (a mod (b*c))/ b

所以就等于(a1^(n1+1)-1)mod (9901*(a1-1)) / (a1-1)。

至于前面的a1^(n1+1),快速幂。

 #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#define mod 9901
#define N 10007
#define ll long long
using namespace std; int prime[]; void getPrime()
{
for(int i=;i<=;i++)
{
if(!prime[i])prime[++prime[]]=i;
for(int j=;j<=prime[]&&prime[j]*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;
}
long long pow_m(long long a,long long n)//快速模幂运算
{
ll ans=;a%=mod;
while(n)
{
if (n&) ans=(ans*a)%mod;
n>>=;
a=(a*a)%mod;
}
return ans;
}
long long sum(long long p,long long n)//计算1+p+p^2+````+p^n
{
if(p==)return ;
if(n==)return ;
if(n&) return ((+pow_m(p,n/+))%mod*sum(p,n/)%mod)%mod;
else return ((+pow_m(p,n/+))%mod*sum(p,n/-)+pow_m(p,n/)%mod)%mod; }
int main()
{
int A,B;
getPrime();
while(~scanf("%d%d",&A,&B))
{
getFactors(A);
long long ans=;
for(int i=;i<fatCnt;i++)
ans=(ans*sum(factor[i][],B*factor[i][])%mod)%mod;
printf("%lld\n",ans);
}
}

poj1845 数论 快速幂的更多相关文章

  1. ACM数论-快速幂

    ACM数论——快速幂 快速幂定义: 顾名思义,快速幂就是快速算底数的n次幂.其时间复杂度为 O(log₂N), 与朴素的O(N)相比效率有了极大的提高. 原理: 以下以求a的b次方来介绍: 把b转换成 ...

  2. BZOJ3561 DZY Loves Math VI 数论 快速幂 莫比乌斯反演

    原文链接http://www.cnblogs.com/zhouzhendong/p/8116330.html UPD(2018-03-26):回来重新学数论啦.之前的博客版面放在更新之后的后面. 题目 ...

  3. BZOJ-1008 越狱 数论快速幂

    1008: [HNOI2008]越狱 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 6192 Solved: 2636 [Submit][Status] ...

  4. hdu-5698 瞬间移动(数论+快速幂)

    题目链接: 瞬间移动 Problem Description   有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右下方格子,并瞬移过去(如从下图中的红色格子能直接瞬移到蓝 ...

  5. 【bzoj2242】: [SDOI2011]计算器 数论-快速幂-扩展欧几里得-BSGS

    [bzoj2242]: [SDOI2011]计算器 1.快速幂 2.扩展欧几里得(费马小定理) 3.BSGS /* http://www.cnblogs.com/karl07/ */ #include ...

  6. HDU 5451 Best Solver 数论 快速幂 2015沈阳icpc

    Best Solver Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)Tota ...

  7. POJ 3641 Pseudoprime numbers (数论+快速幂)

    题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a ...

  8. BZOJ3560 DZY Loves Math V 数论 快速幂

    原文链接http://www.cnblogs.com/zhouzhendong/p/8111725.html UPD(2018-03-26):蒟蒻回来重新学数论了.更新了题解和代码.之前的怼到后面去了 ...

  9. 【bzoj2751】[HAOI2012]容易题(easy) 数论-快速幂

    [bzoj2751][HAOI2012]容易题(easy) 先考虑k=0的情况 那么第一个元素可能为[1,n] 如果序列长度为m-1时的答案是ans[m-1] 那么合并得 然后同理答案就是 k很小 而 ...

随机推荐

  1. 205 Isomorphic Strings 同构字符串

    给定两个字符串 s 和 t,判断它们是否是同构的.如果 s 中的字符可以被替换最终变成 t ,则两个字符串是同构的.所有出现的字符都必须用另一个字符替换,同时保留字符的顺序.两个字符不能映射到同一个字 ...

  2. mysql 中 时间函数 now() current_timestamp() 和 sysdate() 比较

    转载请注明出处 https://www.cnblogs.com/majianming/p/9647786.html 在mysql中有三个时间函数用来获取当前的时间,分别是now().current_t ...

  3. Java-超市购物小票案例-详细介绍

    1.1  超市购物购物小票需求分析 用户循环进行三个操作: 1.输入购买数量,代表为所购买货物的数量赋值,从而计算每项商品金额 2.打印小票,将已有数据打印 3.退出系统(因为该程序为循环操作,无法终 ...

  4. AJPFX总结在循环中break与continue的区别

    相信刚学编程的人很容易被break,continue这两个关键词搞混淆了,两者都有跳出循环的意思,但是他们到底有什么区别呢?其实很简单,break是结束整个循环体,continue是结束当前这一单次循 ...

  5. Android开发中使用代码删除数据库

    更多信息参考:Android开发中使用代码删除数据库 在Android开发中,如果用到数据库,就会有一个很麻烦的问题,就是有时候需要删除数据库很麻烦,要打开Android Device Monitor ...

  6. CCF|打酱油|Java

    import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = ...

  7. VS项目属性配置总结

    以下是针对VS2013下的VC++项目: Debug和Release说明: Debug 通常称为调试版本,它包含调试信息,并且不作任何优化,便于程序员调试程序.Release 称为发布版本,它往往是进 ...

  8. Android源码之陌陌源码

    本源码是一个老版本的陌陌源码,翻了翻代码,发现有完整的登陆注册功能(基于本地)其余都是静态页面.有需要的朋友可以拿去研究一下.其中登陆账号是86930007密码为123456.   这个项目源码我也上 ...

  9. 用Go向MySQL导入.csv文件

    今天来更新一个很少碰到,但碰到了又让人十分蛋疼的问题——Go语言中执行MySQL的load data local infile语句报local file 'xxx' is not registered ...

  10. Discuz!代码

    我如何使用Discuz!代码   Discuz!代码 效果 [b]粗体文字 Abc[/b] 粗体文字 Abc [i]斜体文字 Abc[/i] 斜体文字 Abc [u]下划线文字 Abc[/u] 下划线 ...