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. 【转】linux之fsck命令

    转自:http://www.linuxso.com/command/fsck.html 使用权限 : 超级使用者 使用方式 : fsck [-sACVRP] [-t fstype] [--] [fsc ...

  2. jQuery需要掌握的技巧

    检查 jQuery 是否加载 在使用 jQuery 进行任何操作之前,你需要先确认它已经加载: if (typeof jQuery == 'undefined') { console.log('jQu ...

  3. Spring配置数据库固定代码

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" > &l ...

  4. js代码大全

    超级实用且不花哨的js代码大全 事件源对象event.srcElement.tagNameevent.srcElement.type 捕获释放event.srcElement.setCapture() ...

  5. 五种情况会导致Session 丢失

    1.Session到期自定丢失.2.当修改web.config 系统会重启  SESSION 会丢失.3.Bin目录有变化时候系统会重启 SESSION会丢失 (这里变化指的是,创建新文件.修改文件名 ...

  6. <转>揭秘DNS后台文件:DNS系列之五

    揭秘DNS后台文件 在前面的博文中我们介绍了DNS的体系结构,常用记录,还介绍了辅助服务器的配置,今天我们来介绍一下DNS服务器背后的几个文件.其实DNS服务器的工作完全依靠这几个文件,了解了DNS的 ...

  7. 横版动作MOBA《超宇宙》首测试玩曝光 详解游戏特色(转)

    http://play.163.com/15/0911/11/B37RHHO100314J6L.html

  8. 【LeetCode】111 - Minimum Depth of Binary Tree

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  9. openstack 基本配置

  10. 解决SQLServer2008 Express远程连接出错的问题[Error: 1326错误]

    sqlserver2008 Express版本默认是只能本机测试连接,不能被其他客户端访问,原因是因为Express版本的数据库被连接默认的TCP/IP监听是被关闭的,我们可以做一些设置实现我们的远程 ...