Sumdiv
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 13959   Accepted: 3433

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). 

Source

Romania OI 2002

思路看:

http://hi.baidu.com/necsinmyway/item/9f10b6d96c5068fbb2f77740

AC代码:

#include<iostream>
using namespace std;
#define LL long long
LL pow_mod(LL a,LL n,int mod){ //高速幂
LL r=1;
LL base=a;
while(n){
if(n&1)
r=r*base%mod;
base=base*base%mod;
n>>=1;
}
return r%9901;
}
LL sum(LL a,LL b,LL mod){ //二分求等比数列前N项和
if(b==0)
return 1;
if(b%2==1)
return (sum(a,b/2,mod)*(pow_mod(a,b/2+1,mod)+1))%mod;
else
return (sum(a,b-1,mod)+pow_mod(a,b,mod))%mod;
}
int main(){
LL a,b;
LL ans;
while(cin>>a>>b){
ans=1;
for(LL i=2;i*i<=a;i++){ //将a分解为质数的乘积
if(a%i==0){
LL s=0;
while(a%i==0){
s++;
a/=i;
}
ans=ans*sum(i%9901,b*s,9901)%9901;
}
}
if(a>=2){
ans=ans*sum(a%9901,b,9901)%9901;
}
cout<<ans<<endl;
}
return 0;
}

poj 1845(等比数列前n项和及高速幂)的更多相关文章

  1. 【POJ 1845】 Sumdiv (整数唯分+约数和公式+二分等比数列前n项和+同余)

    [POJ 1845] Sumdiv 用的东西挺全 最主要通过这个题学了约数和公式跟二分求等比数列前n项和 另一种小优化的整数拆分  整数的唯一分解定理: 随意正整数都有且仅仅有一种方式写出其素因子的乘 ...

  2. C - Reading comprehension 二分法 求等比数列前N项和

    Read the program below carefully then answer the question. #pragma comment(linker, "/STACK:1024 ...

  3. poj 3735 大数量反复操作问题(矩阵高速幂)

    题意:一个一维数组,3种操作: a:  第i个数+1,b: 第i个数=0 ,c::交换某俩处的数.  由三种基本操作构成一组序列,反复该序列m次(m<10^9),问结果 属于一种综合操作反复型: ...

  4. poj 3233 Matrix Power Series(矩阵二分,高速幂)

    Matrix Power Series Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 15739   Accepted:  ...

  5. POJ 2478 Farey Sequence(欧拉函数前n项和)

    A - Farey Sequence Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  6. poj 1845 【数论:逆元,二分(乘法),拓展欧几里得,费马小定理】

    POJ 1845 题意不说了,网上一大堆.此题做了一天,必须要整理一下了. 刚开始用费马小定理做,WA.(poj敢说我代码WA???)(以下代码其实都不严谨,按照数据要求A是可以等于0的,那么结果自然 ...

  7. 数列的前$n$项和$S_n$的求法

    相关公式 ①等差数列的\(S_n=\cfrac{n(a_1+a_n)}{2}=na_1+\cfrac{n(n-1)\cdot d}{2}\) ②等比数列的\(S_n=\left\{\begin{arr ...

  8. 求等差数列前$n$项和$S_n$的最值

    一.方法依据: 已知数列\(\{a_n\}\)是等差数列,首项为\(a_1\),公差为\(d\),前\(n\)项和为\(S_n\),则求\(S_n\)的最值常用方法有两种: (1).函数法:由于\(S ...

  9. 数列前n项和

    等差数列 等比数列 常见的前n项和

随机推荐

  1. java --- 设计模式 --- 动态代理

    Java设计模式——动态代理 java提供了动态代理的对象,本文主要探究它的实现, 动态代理是AOP(面向切面编程, Aspect Oriented Programming)的基础实现方式, 动态代理 ...

  2. linux(centos7)下安装tomcat7

    1.下载tomcat1.7.tar.gz 2.将文件放到/usr/local中 #cp tomcat1.7.tar.gz /usr/local 3.进入到/usr/local中,解压缩tomcat1. ...

  3. servicestack操作redis

    tatic void Main(string[] args) { );//redis服务IP和端口 #region =insert= var storeMembers = new List<st ...

  4. ShellExecute的各种用法

    一.利用系统默认的邮件收发器发送电子邮件 Uses ..., ShellAPI; Var lpHwnd: HWND; lpOperation, lpFile, lpParameters, lpDire ...

  5. DzzOffice1.0 Beta2 全新安装图文教程及界面简单了解

    本文说明:本文档用于帮助您全新安装完整的 DzzOffice Beta版软件.DzzOffice 是一款开源的云存储与应用管理工具,主要用于企业管理阿里云.亚马逊等云存储等空间,把空间可视化分配给成员 ...

  6. 验证dictionary重复键

    if (dict.ContainsKey("sadsa")) { }

  7. ubuntu 彻底删除软件包

    找到此软件名称,然后sudo apt-get purge ......(点点为为程序名称),purge参数为彻底删除文件,然后sudo apt-get autoremove,sudo apt-get ...

  8. 第三百二十二天 how can I 坚持

    昨晚好像一直在做梦,模模糊糊的,其实很难受. 真不知道该怎么办了,是没有勇气,还是怕什么,总之, 不知道该咋办了. 搞不懂. 回来第二天了,节奏又一点的开始了,一年又会很快过去. 刘松说要来北京,整天 ...

  9. TransactionScope事务对多个数据库的操作

    .Net 2.0引入了轻量级事务管理器(Lighweight Transaction Manager),即System.Transactions.TransactionManager. 轻量级事务管理 ...

  10. ProxyFactory的一个问题

    今天写了一段很简单的代码,但一直都有问题.代码如下. 接口定义 using System; using System.Collections.Generic; using System.Linq; u ...