Sumdiv
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
题意: 输入A , B. 求 A^B所有因子的和 mod 9901
个人思路:
1.规模大,同余求模,归类为数论题.
2.回忆三个公式: (递推的关键)
(a+b) mod n = ((a mod n) + (b mod n)) mod n ①
(a-b) mod n = ((a mod n) - (b mod n) + n) mod n ②
ab mod n = (a mod n) (b mod n) mod n ③
3.天真的想法: 二分 a^n 对 m 求余后 , 用公式①暴力求解(0~n) 题意弄错了.
题意是求A^B得因子的累加和.
纠正后发现:
排列组合的思维: A^B的因子的和. 设p1,p2,p3...pn是A得质因子.
推出公式: (p1^0+p1^1+...p1^B)*(P2^0+P2^1+...+P2^B)*...*(pn^0+pn^1+...+pn^B)
网上发现:
计算 1 + P + P^2 + P^3 +...+ P ^B 可用二分求解;
当k是偶数时: 例如k=4,1 + P + P^2 + P^3 + P^4 = (1+P) + P^2 * (1+P*(1+P));
当k是奇数时: 例如k=5,1 + P + P^2 + P^3 + P^4 + P^5 = (1 + P + P^2) + P^3 * (1 + P + P^2);
(两次二分速度就很快乐了!!)
代码:
#include
<iostream>
#include <cstdio>
#include <string.h>
using namespace std;
#define mod 9901
#define MAX 100005
int a[MAX] = {0}; //个数
int b[MAX] = {0}; //因子
__int64 pow_mod(__int64 a,__int64
n)
{
}
__int64 sum(__int64 a,__int64 n)
{
}
int main()
{
while(scanf("%I64d
%I64d",&A,&B) != EOF)
if(A != 1)
__int64 result = 1;
return 0;
}