Sumdiv
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 22680   Accepted: 5660

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的所有约数的和
【题解】
  把A唯一分解,不难得到答案:
   (1+p1+p1^2+……+p1^(φ1*B)) × (1+p2+p2^2+
  ……+p2^(φ2*B)) ×……× (1+pn+pn^2+……+pn^(φn*B))
  问题转化为等比数列求和,此处MOD为质数,存在逆元,但对于更一般的情况,采用分治法,复杂度多一个Log
  cal(p,k) = p^0 + p^1 + p^2 + ... + p^k
  if k&1
    cal(p,k) = (1 + p^((k + 1)/2))*cal(p, (k-1)/2)
  else
    cal(p,k) = (1 + p^(k/2)) * cal(p, k/2 - 1) + p^k
  快速幂即可
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath> const int INF = 0x3f3f3f3f;
const int MAXN = + ;
const int MOD = ; inline void read(int &x)
{
x = ;char ch = getchar();char c = ch;
while(ch > '' || ch < '')c = ch, ch = getchar();
while(ch <= '' && ch >= '')x = x * + ch - '', ch = getchar();
if(c == '-')x = -x;
} int a,b,cnt,xishu[],zhishu[],ans; int pow(int p, int k)
{
int r = , base = p;
for(;k;k >>= )
{
if(k & )r = ((long long)r * base) % MOD;
base = ((long long)base * base % MOD);
}
return r % MOD;
} //求解1 + p + p^2 + p^3 + ... + p^k
int cal(int p, int k)
{
if(k == ) return ;
if(k == ) return (p + ) % MOD;
if(k & ) return ((long long)( + pow(p, (k + )/)) * (long long)(cal(p, (k - )/))%MOD) % MOD;
else return((long long)(pow(p, k/) + ) * (long long)(cal(p, k/ - )) % MOD + pow(p, k)) % MOD;
} int main()
{
read(a),read(b);
register int nn = sqrt(a) + ;
for(register int i = ;i <= nn && a > ;++ i)
if(a % i == )
{
zhishu[++cnt] = i;
while(a % i == ) ++ xishu[cnt], a /= i;
}
if(a > )zhishu[++cnt] = a, xishu[cnt] = ;
ans = ;
for(register int i = ;i <= cnt;++ i)
{
ans *= cal(zhishu[i], xishu[i] * b);
ans %= MOD;
}
printf("%d", ans%MOD);
return ;
}

POJ1848 Sumdiv

POJ1485 Sumdiv的更多相关文章

  1. POJ 1845 Sumdiv

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

  2. Sumdiv(快速幂+约数和)

    Sumdiv Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16244 Accepted: 4044 Description C ...

  3. poj 1845 Sumdiv 约数和定理

    Sumdiv 题目连接: http://poj.org/problem?id=1845 Description Consider two natural numbers A and B. Let S ...

  4. Sumdiv 等比数列求和

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

  5. poj 1845 POJ 1845 Sumdiv 数学模板

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

  6. 『sumdiv 数学推导 分治』

    sumdiv(POJ 1845) Description 给定两个自然数A和B,S为A^B的所有正整数约数和,编程输出S mod 9901的结果. Input Format 只有一行,两个用空格隔开的 ...

  7. POJ 1845 Sumdiv(逆元)

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

  8. poj1845 Sumdiv

    poj1845 Sumdiv 数学题 令人痛苦van分的数学题! 题意:求a^b的所有约数(包括1和它本身)之和%9901 这怎么做呀!!! 百度:约数和定理,会发现 p1^a1 * p2^a2 * ...

  9. 一本通1633【例 3】Sumdiv

    1633:[例 3]Sumdiv 时间限制: 1000 ms         内存限制: 524288 KB [题目描述] 原题来自:Romania OI 2002 求 ABAB 的所有约数之和 mo ...

随机推荐

  1. sscanf linux-c从一个字符串中读进与指定格式相符的数据

    https://www.cnblogs.com/lanjianhappy/p/6861728.html 函数原型: Int sscanf( string str, string fmt, mixed ...

  2. lc6 ZigZag Conversion

    lc6 ZigZag Conversion 分成两步, 第一步垂直向下, 1 1 1 1 第二步倾斜向上 1 1 1 1 1 1 1 用nRows个StringBuilder 然后将他们合并即可 cl ...

  3. 阿里云HBase Ganos全新升级,推空间、时空、遥感一体化基础云服务

    1.HBase Ganos是什么 Ganos是阿里云时空PaaS服务的自研核心引擎.Ganos已作为云数据库时空引擎与数据库平台融合,建立了以自研云原生数据库POALRDB为基础,联合NoSQL大数据 ...

  4. 在sqlserver 的函数或存储过程中抛出异常(raiserror )

      raiserror的作用: raiserror 是用于抛出一个错误 其语法如下: RAISERROR ( { msg_id | msg_str | @local_variable } { ,sev ...

  5. css3之文本和颜色功能之text-overflow,word-wrap

    语法 text-overflow: clip|ellipsis|string; clip修剪文本.ellipsis显示省略符号来代表被修剪的文本.string使用给定的字符串来代表被修剪的文本. 效果 ...

  6. 2019-8-31-dotnet-通过-WMI-获取指定进程的输入命令行

    title author date CreateTime categories dotnet 通过 WMI 获取指定进程的输入命令行 lindexi 2019-08-31 16:55:59 +0800 ...

  7. 解释性语言和非解释性语言,GIL锁

    解释性语言:python写的代码就被称为程序,cpu硬件能运行二进制代码指令.demo.py需要经过python解释器编译才做才能执行. 非解释性语言:例如c语言程序,同样需要写代码.demo.c这个 ...

  8. Ubuntu 解压和压缩总结

    1..rar文件 一般通过默认安装的ubuntu是不能解压rar文件的,只有在安装了rar解压工具之后,才可以解压.其实在ubuntu下安装rar解压工具非常简单,下面是具体方法: ubuntu 下r ...

  9. angular7.X配置同时使用localhost和本机IP访问项目

    1.项目中找到此文件“node_modules/webpack-dev-server/lib/Server.js”,按照下图修改: 二.修改配置文件package.json,见下图: 三.npm st ...

  10. Frank Dellaert Slam Speech 20190708

    Georgia Institue of Tecknology 3D Models from Community Databases Spatiotemporal Reconstruction 4D C ...