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. Raspberry Pi3 ~ 配置网络

    Rpi3 有两个网卡 一个无线wlan 一个有线 eth0 无线的只需要在右上角的那个配置里面添加就行 有线的需要设置下静态IP.dns.等 在raspbain图形化界面里面 设置 Network P ...

  2. 单源最短路径的Bellman-Ford 算法

    1.算法标签 BFS 2.算法概念 Bellman-Ford算法有这么一个先验知识在里面,那就是最短路径至多在N步之内,其中N为节点数,否则说明图中有负权值的回路,这样的图是找不到最短路径的.因此Be ...

  3. Struts Convention Plugin 流程 (2.1.6+)

    首先添加lib: <dependency> <groupId>org.apache.struts</groupId> <artifactId>strut ...

  4. 【openstack报错】【因更新包而致】IncompatibleObjectVersion: Version 1.9 of Instance is not supported

    [时间]2014年2月18日 [平台]ubuntu 12.04.3 openstack havana [日志]/var/log/upstart/nova-compute.log  内容如下: ERRO ...

  5. HW7.13

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  6. URAL-1987 Nested Segments 线段树简单区间覆盖

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1987 题意:给定n条线段,每两条线段要么满足没有公共部分,要么包含.给出m个询问,求当前 ...

  7. Android:控件WebView显示网页 -摘自网络

    WebView可以使得网页轻松的内嵌到app里,还可以直接跟js相互调用. webview有两个方法:setWebChromeClient 和 setWebClient setWebClient:主要 ...

  8. Chef

    Chef是一个渐渐流行的部署大.小集群的自动化管理平台.Chef可以用来管理一个传统的静态集群,也可以和EC2或者其他的云计算提供商一起使用.Chef用cookbook作为最基本的配置单元,可以被泛化 ...

  9. rdlc 分页操作

    工具箱中拖一个列表过来,设置 列表-->行组-->组属性常规-->组表达式=Int((RowNumber(Nothing)-1)/10)分页符-->勾选在组的结尾

  10. shell调试选项

    [shell调试选项] 一些常用选项的用法: -n 只读取shell脚本,但不实际执行 -x 进入跟踪方式,显示所执行的每一条命令 -c "string" 从strings中读取命 ...