Sumdiv

题目连接:

http://poj.org/problem?id=1845

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

题意

给你A,B,求A^B的因子和mod 9901

题解:

首先我们知道A的因式分解

A = (p1^k1) * (p2^k2) * (p3^k3) * .... * (pn^kn)

所以A^B = (p1^(k1*B)) * (p2^(k2*B)) * (p3^(k3*B)) * .... * (pn^(kn*B))

然后根据约数和定理,约数的和

Sum = (1+p1+p12+...+p1(k1*B))(1+p2....+p2(k2*B)).....(1+pn+...+pn(kn*B))

中间等比数列要mod,所以就直接递归求就好了。

代码

#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
const int maxn = 1e6;
long long quickpow(long long m,long long n,long long k)
{
long long b = 1;
while (n > 0)
{
if (n & 1)
b = (b*m)%k;
n = n >> 1 ;
m = (m*m)%k;
}
return b;
}
int cnt[maxn];
int num[maxn];
int tot = 0;
void factorization(int x)
{
for(int i=2;i*i<=x;i++)
{
if(x%i==0)
{
cnt[tot]=i;
num[tot]=0;
while(x%i==0)
{
x/=i;
num[tot]++;
}
tot++;
}
}
if(x!=1)
{
cnt[tot]=x;
num[tot]=1;
tot++;
}
} long long Sum_of_geometric_progression(long long p,long long n,long long mod)
{
if(n==0)return 1;
if(n&1)
return ((1+quickpow(p,n/2+1,mod))%mod*Sum_of_geometric_progression(p,n/2,mod)%mod)%mod;
else
return (quickpow(p,n/2,mod)+(1+quickpow(p,n/2+1,mod))%mod*Sum_of_geometric_progression(p,(n-1)/2,mod)%mod)%mod;
} int main()
{
int A,B;
while(scanf("%d%d",&A,&B)!=EOF)
{
tot = 0;
factorization(A);
int ans = 1;
for(int i=0;i<tot;i++)
ans = (ans*Sum_of_geometric_progression(cnt[i],B*num[i],9901))%9901;
printf("%d\n",ans);
}
return 0;
}

poj 1845 Sumdiv 约数和定理的更多相关文章

  1. poj 1845 POJ 1845 Sumdiv 数学模板

    筛选法+求一个整数的分解+快速模幂运算+递归求计算1+p+p^2+````+p^nPOJ 1845 Sumdiv求A^B的所有约数之和%9901 */#include<stdio.h>#i ...

  2. poj 1845 Sumdiv(约数和,乘法逆元)

    题目: 求AB的正约数之和. 输入: A,B(0<=A,B<=5*107) 输出: 一个整数,AB的正约数之和 mod 9901. 思路: 根据正整数唯一分解定理,若一个正整数表示为:A= ...

  3. POJ 1845 Sumdiv 【二分 || 逆元】

    任意门:http://poj.org/problem?id=1845. Sumdiv Time Limit: 1000MS Memory Limit: 30000K Total Submissions ...

  4. POJ 1845 Sumdiv [素数分解 快速幂取模 二分求和等比数列]

    传送门:http://poj.org/problem?id=1845 大致题意: 求A^B的所有约数(即因子)之和,并对其取模 9901再输出. 解题基础: 1) 整数的唯一分解定理: 任意正整数都有 ...

  5. POJ 1845 Sumdiv#质因数分解+二分

    题目链接:http://poj.org/problem?id=1845 关于质因数分解,模板见:http://www.cnblogs.com/atmacmer/p/5285810.html 二分法思想 ...

  6. POJ 1845 Sumdiv(逆元)

    题目链接:Sumdiv 题意:给定两个自然数A,B,定义S为A^B所有的自然因子的和,求出S mod 9901的值. 题解:了解下以下知识点   1.整数的唯一分解定理 任意正整数都有且只有唯一的方式 ...

  7. POJ 1845 Sumdiv (整数唯一分解定理)

    题目链接 Sumdiv Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 25841   Accepted: 6382 Desc ...

  8. poj 1845 Sumdiv (等比求和+逆元)

    题目链接:http://poj.org/problem?id=1845 题目大意:给出两个自然数a,b,求a^b的所有自然数因子的和模上9901 (0 <= a,b <= 50000000 ...

  9. POJ 1845 Sumdiv

    快速幂+等比数列求和.... Sumdiv Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12599 Accepted: 305 ...

随机推荐

  1. 【剑指offer 面试题27】二叉搜索树与双向链表

    输入一颗二叉搜索树,将该二叉搜索树转换成一个排序的双向链表. C++: #include <iostream> using namespace std; struct TreeNode { ...

  2. Independence独立

    Independence refers to the degree to which each test case stands alone. That is, does the success or ...

  3. 我的window平台下的软件

    SocksCap64-Portable-3.0(配合google drive 使用) ShadowsocksR-win-3.7.4 dropbox xx-net chrome switchyomega ...

  4. VS如何设置OpenCV静态编译

      可以使用opencv提供的静态链接库也可以自己编译静态链接库. 1 使用opencv提供的静态链接库,位置如下图. 首先设置VS配置.有如下几个配置 1 工具->选项->项目和解决方案 ...

  5. 骑士周游问题 --- 递归解法 --- java代码

    骑士游历: 定义了向量的数组M,行数组X,列数组Y, 棋盘plane,计数器count,走动步数step 需要注意的是,递归函数的进入前的验证,原先的想法是传入来时的方向参数,可是这样的想法被实践否定 ...

  6. 【quick-cocos2d-x】Lua 面向对象(OOP)编程与元表元方法

    版权声明:本文为博主原创文章,转载请注明出处. 面向对象是一种对现实世界理解和抽象的方法,是计算机编程技术发展到一定阶段后的产物. 早期的计算机编程是基于面向过程的方法,通过设计一个算法就可以解决当时 ...

  7. Intent相关

    Intent是什么? 翻译为:意图,目的(名词) 其实根本没必要管它是什么,看看它能做什么就好了. 不过后来我知道了,它就是个机制----通信机制-----android的许多组件间的交流要依赖它. ...

  8. Windows Azure 设置虚拟机静态外网IP地址

    官方说法叫做“虚拟公共IP地址保留”,为容易理解,我们称之为静态外网IP地址. 如果在国内使用国际版Windows Azure服务时强烈推荐为虚拟机设置IP地址保留. 由于Windows Azure ...

  9. Make the “Check out” function available in the office document opened with Document ID link

    I found a solution to make the “Check out” function available in the office document opened with Doc ...

  10. fdquery update

    fdquery  update this->FDQuery1->CachedUpdates; this->FDQuery1->UpdateOptions->KeyFiel ...