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. MySql通用分页存储过程

    MySql通用分页存储过程 1MySql通用分页存储过程 2 3过程参数 4p_cloumns varchar(500),p_tables varchar(100),p_where varchar(4 ...

  2. hdu 1166 敌兵布阵(线段树单点更新,区间查询)

    题意:区间和 思路:线段树 #include<iostream> #include<stdio.h> using namespace std; #define MAXN 500 ...

  3. js 判断页面是否加载完成

    javascript代码如下: document.onreadystatechange = subSomething; //当页面加载状态改变的时候执行这个方法 function subSomethi ...

  4. 全方位掌握 NSIS 的操作

    NSIS 确实是一个不错的安装程序制作软件.新版本2.0a7真正实现了中文支持和支持 WinXP 的安装对话框.不过要用它实现漂亮的安装界面和完美的安装功能就必须好好的写脚本.而 NSIS 的脚本指令 ...

  5. bzoj 2038 [2009国家集训队]小Z的袜子(hose)(莫队算法)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2038 [题意] 给定一个有颜色的序列,回答若干个询问:区间内任选两个颜色相同的概率. ...

  6. (转载)OC学习篇之---Foundation框架中的NSArray类和NSMutableArray类

    在之前的一篇文章中介绍了Foundation框架中的NSString类和NSMutableString类,今天我们继续来看一下Foundation框架中的NSArray类和NSMutableArray ...

  7. 有趣的库:pipe(类似linux | 管道)库

    pipe并不是Python内置的库,如果你安装了easy_install,直接可以安装它,否则你需要自己下载它:http://pypi.python.org/pypi/pipe 之所以要介绍这个库,是 ...

  8. (转)QR二维码生成及原理

    二维码又称QR Code,QR全称Quick Response,是一个近几年来移动设备上超流行的一种编码方式,它比传统的Bar Code条形码能存更多的信息,也能表示更多的数据类型:比如:字符,数字, ...

  9. 【原创】开发Kafka通用数据平台中间件

    开发Kafka通用数据平台中间件 (含本次项目全部代码及资源) 目录: 一. Kafka概述 二. Kafka启动命令 三.我们为什么使用Kafka 四. Kafka数据平台中间件设计及代码解析 五. ...

  10. Chapter 3 Start Caffe with MNIST Demo

    先从一个具体的例子来开始Caffe,以MNIST手写数据为例. 1.下载数据 下载mnist到caffe-master\data\mnist文件夹. THE MNIST DATABASE:Yann L ...