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. Service官方教程(4)两种Service的生命周期函数

    Managing the Lifecycle of a Service The lifecycle of a service is much simpler than that of an activ ...

  2. C#---数据库访问通用类、Access数据库操作类、mysql类 .[转]

    原文链接 //C# 数据库访问通用类 (ADO.NET)using System;using System.Collections.Generic;using System.Text;using Sy ...

  3. java数组实现买彩票(重复则重新遍历查询思想)

    package com.wh.shuzu; import java.util.Arrays; /** * 买彩票 * @author 丁璐同学 * 重复则重新遍历查询思想 */ public clas ...

  4. Eclipse快捷键集合

    ***eclipse查看哪个方法被调用:选中,右键选择Open call Hierarchy     选择要查看的方法: ctrl + alt + h       查看一个类被那些类继承或者实现: F ...

  5. C# 控制台语音计算器

    记得上高中时,给人当会计,帮忙结算月度工资:用的就是带语音功能的计算器! 当时用起来倍儿爽,于是速度加倍,效率加速:结果让老板赔了不少钱! 就是因为这个,才对语音计算器有了深刻印象!可能是这货坑了我! ...

  6. JSR-303原生支持的限制

    @Null: 限制只能为null@NotNull: 限制必须不为null@AssertFalse: 限制必须为false@AssertTrue: 限制必须为true@DecimalMax(value) ...

  7. 前台js获得json数据

    $.ajax({ type:"post", url:"testAction.action", data:{ classId:classId }, success ...

  8. Dragger2解析(一)

    依赖注入(DI-Dependency Injection) 什么是依赖注入 这是一种设计思想,一个面向对象的编程法则. DI能够让开发者写出低耦合代码,更加优良的程序. 更容易测试,代码健壮性更强. ...

  9. HTML5——loading

    https://www.cnblogs.com/wangmeijian/p/4449150.html https://www.cnblogs.com/yunser/p/canvas-baidu-loa ...

  10. eclipse 升级note

    参考http://www.cnblogs.com/jiqingwu/archive/2013/05/26/eclipse_plugins_import.html. 最终决定采用 启动 eclipse. ...