poj 1845 Sumdiv 约数和定理
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 约数和定理的更多相关文章
- poj 1845 POJ 1845 Sumdiv 数学模板
筛选法+求一个整数的分解+快速模幂运算+递归求计算1+p+p^2+````+p^nPOJ 1845 Sumdiv求A^B的所有约数之和%9901 */#include<stdio.h>#i ...
- poj 1845 Sumdiv(约数和,乘法逆元)
题目: 求AB的正约数之和. 输入: A,B(0<=A,B<=5*107) 输出: 一个整数,AB的正约数之和 mod 9901. 思路: 根据正整数唯一分解定理,若一个正整数表示为:A= ...
- POJ 1845 Sumdiv 【二分 || 逆元】
任意门:http://poj.org/problem?id=1845. Sumdiv Time Limit: 1000MS Memory Limit: 30000K Total Submissions ...
- POJ 1845 Sumdiv [素数分解 快速幂取模 二分求和等比数列]
传送门:http://poj.org/problem?id=1845 大致题意: 求A^B的所有约数(即因子)之和,并对其取模 9901再输出. 解题基础: 1) 整数的唯一分解定理: 任意正整数都有 ...
- POJ 1845 Sumdiv#质因数分解+二分
题目链接:http://poj.org/problem?id=1845 关于质因数分解,模板见:http://www.cnblogs.com/atmacmer/p/5285810.html 二分法思想 ...
- POJ 1845 Sumdiv(逆元)
题目链接:Sumdiv 题意:给定两个自然数A,B,定义S为A^B所有的自然因子的和,求出S mod 9901的值. 题解:了解下以下知识点 1.整数的唯一分解定理 任意正整数都有且只有唯一的方式 ...
- POJ 1845 Sumdiv (整数唯一分解定理)
题目链接 Sumdiv Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 25841 Accepted: 6382 Desc ...
- poj 1845 Sumdiv (等比求和+逆元)
题目链接:http://poj.org/problem?id=1845 题目大意:给出两个自然数a,b,求a^b的所有自然数因子的和模上9901 (0 <= a,b <= 50000000 ...
- POJ 1845 Sumdiv
快速幂+等比数列求和.... Sumdiv Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12599 Accepted: 305 ...
随机推荐
- J2EE事务
一.J2EE 事务处理方式 1. 本地事务:紧密依赖于底层资源管理器(例如数据库连接 ),事务处理局限在当前事务资源内.此种事务处理方式不存在对应用服务器的依赖,因而部署灵活却无法支持多数据源的分布式 ...
- Mac OS 10.8 中的 OpenCV 开发环境设置
一.编译OpenCV 要在Mac OS上使用OpenCV,需要自己编译源代码.操作过程如下: 1)从http://www.cmake.org下载cmake 2.8安装包. 2)安装cmake 2.8. ...
- windows中安装python
windows中安装python 在windows中安装python的步骤如下. 1.下载python的安装包 python的安装包地址为: https://www.python.org/ftp/py ...
- 多线程的Python 教程--“贪吃蛇”
本指南的里代码可以在这里下载: threadworms.py ,或者从 GitHub.代码需要 Python 3 或 Python 2 ,同时也需要安装 Pygame . 点击查看大版本图片 ...
- 9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路
1,简介 毕业答辩搞定,总算可以闲一段时间,把这段求职经历写出来,也作为之前三个半月的求职的回顾. 首先说说我拿到的offer情况: 微软,3面->终面,搞定 百度,3面->终面,口头of ...
- Windows8.1 安装office2013并激活
之前笔记本上安装的东西太多了,启动比较慢,打算重做系统,正好同事有一个Windows8.1的系统盘,直接做了一个Windows8.1的系统.界面清爽,速度还可以,系统安装完成以后,准备安装office ...
- mongodb使用中遇到的问题汇总
1. 每次重新打开mongo,都会显示:forked process:xxxx ,然后用 find -name mongod.lock 进行搜索,发现在 ./var/lib/mongodb/ 目录下又 ...
- android 开发必用的开源库
LogReport: https://github.com/wenmingvs/LogReport, 崩溃日志上传框架 wcl-permission-demo:Android 6.0 - 动态权 ...
- 制作Andriod程序的数字签名需要使用JDK
原文地址:制作Andriod程序的数字签名需要使用JDK作者:黄金大劫案88 制作Andriod程序的数字签名需要使用JDK,先确认本机是否安装了JDK,在JDK目录下有一个KEYTOOL工具,这个 ...
- Linux查找文件夹名
@(编程) find / -type d -name filename type的类型 -type c File is of type c: b block (buffered) special c ...