Sumdiv

Sumdiv
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 15364   Accepted: 3790

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

 
 

大致题意:

求A^B的所有约数(即因子)之和,并对其取模 9901再输出。

解题思路:

要求有较强 数学思维 的题

应用定理主要有三个:

要求有较强 数学思维 的题

应用定理主要有三个:

(1)   整数的唯一分解定理:

任意正整数都有且只有一种方式写出其素因子的乘积表达式。

A=(p1^k1)*(p2^k2)*(p3^k3)*....*(pn^kn)   其中pi均为素数

(2)   约数和公式:

对于已经分解的整数A=(p1^k1)*(p2^k2)*(p3^k3)*....*(pn^kn)

有A的所有因子之和为

S = (1+p1+p1^2+p1^3+...p1^k1) * (1+p2+p2^2+p2^3+….p2^k2) * (1+p3+ p3^3+…+ p3^k3) * .... * (1+pn+pn^2+pn^3+...pn^kn)

(3)   同余模公式:

(a+b)%m=(a%m+b%m)%m

(a*b)%m=(a%m*b%m)%m

有了上面的数学基础,那么本题解法就很简单了:

1: 对A进行素因子分解

分解A的方法:

A首先对第一个素数2不断取模,A%2==0时 ,记录2出现的次数+1,A/=2;

当A%2!=0时,则A对下一个连续素数3不断取模...

以此类推,直到A==1为止。

注意特殊判定,当A本身就是素数时,无法分解,它自己就是其本身的素数分解式。

最后得到A = p1^k1 * p2^k2 * p3^k3 *...* pn^kn.
      故 A^B = p1^(k1*B) * p2^(k2*B) *...* pn^(kn*B);

2:A^B的所有约数之和为:

sum = [1+p1+p1^2+...+p1^(a1*B)] * [1+p2+p2^2+...+p2^(a2*B)] *...* [1+pn+pn^2+...+pn^(an*B)].

3: 用递归二分求等比数列1+pi+pi^2+pi^3+...+pi^n:

(1)若n为奇数,一共有偶数项,则:
      1 + p + p^2 + p^3 +...+ p^n

= (1+p^(n/2+1)) + p * (1+p^(n/2+1)) +...+ p^(n/2) * (1+p^(n/2+1))
      = (1 + p + p^2 +...+ p^(n/2)) * (1 + p^(n/2+1))

上式红色加粗的前半部分恰好就是原式的一半,那么只需要不断递归二分求和就可以了,后半部分为幂次式,将在下面第4点讲述计算方法。

(2)若n为偶数,一共有奇数项,则:
      1 + p + p^2 + p^3 +...+ p^n

= (1+p^(n/2+1)) + p * (1+p^(n/2+1)) +...+ p^(n/2-1) * (1+p^(n/2+1)) + p^(n/2)
      = (1 + p + p^2 +...+ p^(n/2-1)) * (1+p^(n/2+1)) + p^(n/2);

上式红色加粗的前半部分恰好就是原式的一半,依然递归求解

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <iomanip>
#include <cstdlib>
#include <sstream>
using namespace std;
typedef long long LL;
const int INF=0x4fffffff;
const double EXP=1e-;
const int MS=;
const LL mod=; LL pow_mod(LL x,LL n)
{
LL res=;
while(n)
{
if(n&(1LL))
//res=res*x%mod;
res=((res%mod)*(x%mod))%mod;
n>>=;
// x=x*x%mod;
x=(x%mod)*(x%mod);
}
return res;
} LL calc(LL x,LL y) // sigma (0->y) x^i
{
if(y==)
return ;
if(y&(1LL))
return ((calc(x,y/)%mod)*((pow_mod(x,y/+)+)%mod))%mod;
//return calc(x,y/2)*(1+pow_mod(x,y/2+1));
else
return ( ( (calc(x,y/-)%mod)* ( (pow_mod(x,y/+)+)%mod) ) %mod+pow_mod(x,y/) )%mod;
//return calc(x,y/2-1)*(pow_mod(x,y/2+1)+1)+pow_mod(x,y/2);
} LL prime[MS];
LL cnt[MS]; int main()
{
LL x,y;
cin>>x>>y;
LL t=(LL)(sqrt(x*1.0)+EXP);
LL k=;
for(LL i=;i<=t;i++)
{
if(x%i==)
{
prime[k]=i;
while(x%i==)
{
cnt[k]++;
x/=i;
}
k++;
}
}
if(x!=1LL)
{
prime[k]=x;
cnt[k++]=;
} LL ans=1LL;
for(LL i=;i<k;i++)
ans=(ans%mod*calc(prime[i],cnt[i]*y)%mod)%mod;
cout<<ans<<endl;
return ;
}

Sumdiv 等比数列求和的更多相关文章

  1. POJ 1845 (约数和+二分等比数列求和)

    题目链接: http://poj.org/problem?id=1845 题目大意:A^B的所有约数和,mod 9901. 解题思路: ①整数唯一分解定理: 一个整数A一定能被分成:A=(P1^K1) ...

  2. hoj3152-Dice 等比数列求和取模

    http://acm.hit.edu.cn/hoj/problem/view?id=3152 Dice My Tags (Edit) Source : Time limit : sec Memory ...

  3. luogu1397 [NOI2013]矩阵游戏 (等比数列求和)

    一个比较显然的等比数列求和,但有一点问题就是n和m巨大.. 考虑到他们是在幂次上出现,所以可以模上P-1(费马小定理) 但是a或c等于1的时候,不能用等比数列求和公式,这时候就要乘n和m,又要变成模P ...

  4. Codeforces 963A Alternating Sum(等比数列求和+逆元+快速幂)

    题目链接:http://codeforces.com/problemset/problem/963/A 题目大意:就是给了你n,a,b和一段长度为k的只有'+'和‘-’字符串,保证n+1被k整除,让你 ...

  5. bzoj 4555 [Tjoi2016&Heoi2016]求和 NTT 第二类斯特林数 等比数列求和优化

    [Tjoi2016&Heoi2016]求和 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 679  Solved: 534[Submit][S ...

  6. ZOJ-3774 Power of Fibonacci——等比数列求和&&等价替换

    题目 求 $\displaystyle \sum_{i=1}^n F_i^k$,($1 \leq n\leq 10^{18},1 \leq  k\leq 10^5$),答案对 $10^9+9$ 取模. ...

  7. 2019河北省大学生程序设计竞赛(重现赛)B 题 -Icebound and Sequence ( 等比数列求和的快速幂取模)

    题目链接:https://ac.nowcoder.com/acm/contest/903/B 题意: 给你 q,n,p,求 q1+q2+...+qn 的和 模 p. 思路:一开始不会做,后面查了下发现 ...

  8. [zoj 3774]Power of Fibonacci 数论(二次剩余 拓展欧几里得 等比数列求和)

    Power of Fibonacci Time Limit: 5 Seconds      Memory Limit: 65536 KB In mathematics, Fibonacci numbe ...

  9. CodeForces Round #191 (327C) - Magic Five 等比数列求和的快速幂取模

    很久以前做过此类问题..就因为太久了..这题想了很久想不出..卡在推出等比的求和公式,有除法运算,无法快速幂取模... 看到了 http://blog.csdn.net/yangshuolll/art ...

随机推荐

  1. 60分钟内从零起步驾驭Hive实战学习笔记

    本博文的主要内容是: 1. Hive本质解析 2. Hive安装实战 3. 使用Hive操作搜索引擎数据实战 SparkSQL前身是Shark,Shark强烈依赖于Hive.Spark原来没有做SQL ...

  2. JVM系列四:生产环境参数实例及分析【生产环境实例增加中】

    java application项目(非web项目) 改进前: -Xms128m-Xmx128m-XX:NewSize=64m-XX:PermSize=64m-XX:+UseConcMarkSweep ...

  3. [翻译]创建ASP.NET WebApi RESTful 服务(9)

    一旦成功的发布API后,使用者将依赖于你所提供的服务.但是变更总是无法避免的,因此谨慎的制定ASP.NET Web API的版本策略就变得非常重要.一般来说,新的功能需要无缝的接入,有时新老版本需要并 ...

  4. Symbol Table

    [Symbol Table] In order for GDB to be useful to us, it needs to be able to refer to variable and fun ...

  5. hdu 2899 Strange fuction

    http://acm.hdu.edu.cn/showproblem.php?pid=2899 Strange fuction Time Limit: 2000/1000 MS (Java/Others ...

  6. 什么是IntelAMT

    IntelAMT 全称为INTEL主动管理技术,该技术允许IT经理们远程管理和修复联网的计算机系统,而且实施过程是对于服务对象完全透明的,从而节省了用户的时间和计 算机维护成本.释放出来的iAMT构架 ...

  7. class str

    class str(object): """ str(object='') -> str str(bytes_or_buffer[, encoding[, erro ...

  8. Codeforces 444 C. DZY Loves Colors (线段树+剪枝)

    题目链接:http://codeforces.com/contest/444/problem/C 给定一个长度为n的序列,初始时ai=i,vali=0(1≤i≤n).有两种操作: 将区间[L,R]的值 ...

  9. UITextFiled,UIButton,UIImageView交互相互之间的事件拦截

    UIButton右上方添加一个笑button如: UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];    button.f ...

  10. UIWebView 获取当前的javascript上下文,并js,oc互调

    OC调用UIWebView 中的js,网上例子很多,最常用的是UIWebView自带的一个方法: - (NSString *)stringByEvaluatingJavaScriptFromStrin ...