首页 > 其他分享 >POJ 1845Sumdiv(数论)

POJ 1845Sumdiv(数论)

时间:2022-11-18 16:34:50浏览次数:50  
标签:return 9901 数论 sum long ++ POJ 15 1845Sumdiv


Sumdiv


Time Limit: 1000MS

 

Memory Limit: 30000K

Total Submissions: 20041

 

Accepted: 5060


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



#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>

using namespace std;

long long p[100000];
long long k[100000];

long long pows(long long n, long long m)//快速幂
{
long long t = 1;
while(m)
{
if(m%2 != 0)
{
t = (t*n)%9901;
m--;
}
n = (n*n)%9901;
m /= 2;
}
//cout<<t<<endl;
return t;
}

long long mou(long long x,long long y)
{
if(y==0)
return 1;
if(y%2==0)
return (((mou(x,y/2-1)%9901)*((1+pows(x,y/2+1))%9901))%9901+pows(x,y/2)%9901)%9901;
if(y%2!=0)
return (mou(x,y/2)%9901)*((1+pows(x,y/2+1))%9901)%9901;
}
int main()
{
long long m, n, i;
while(~scanf("%lld %lld", &n, &m))
{
int j = 0;
for(i = 2; i <= (int)sqrt(n*1.0); i += 2)
{
if(n%i==0)
{
p[j] = i;
k[j] = 0;
while(n%i==0)
{
k[j]++;
n /= i;
}
}
j++;
if(i == 2)
{
i--;
}
if(n==1)
{
break;
}
}
if(n != 1)
{
p[j] = n;
k[j++] = 1;
}
//以上是分解质因数。
for(i = 0; i < j; i++)
{
//printf("%d %d\n", p[i], k[i]);
k[i] *= m;
}
long long sum = 1;
for(i = 0; i < j; i++)
{
sum = sum * mou(p[i], k[i])%9901;
}
printf("%lld\n", sum);
}
return 0;
}



标签:return,9901,数论,sum,long,++,POJ,15,1845Sumdiv
From: https://blog.51cto.com/u_15879559/5868812

相关文章

  • Feign 实现 GET 方法传递 POJO
    Feign实现GET方法传递POJO作者:Grey原文地址:博客园:Feign实现GET方法传递POJOCSDN:Feign实现GET方法传递POJO需求SpringMVC支持GET方法直接绑定POJO......
  • 牛客小白月赛60 E-寻找小竹!(数论)
    链接:https://ac.nowcoder.com/acm/contest/45670/E来源:牛客网题目大意:有n个城市,n-1条道路,每个城市都有它自己的优雅值ai而如果两个相邻的路口的优雅值存在至少两个共......
  • 【学习笔记】数论
    前言:基本参照OIWIKI数论数论分块参考博客henry_y参考博客Miniqwq常见形式:\[f(n,k)=\sum\limits_{i=1}^{n}\lfloor\frac{k}{i}\rfloor\]画个双曲线图,在图上找到符合......
  • POJ-1417(带权并查集+01背包+回溯)
    TrueLiars题目描述:Peter有一个王国。在这个王国里,一共有2种人,即诚实人和撒谎人。诚实人永远说真话,撒谎人永远说假话。可惜的是,Peter只记得诚实人的数量和撒谎人的数量......
  • POJ 1952 BUY LOW, BUY LOWER
    DescriptionTheadviceto"buylow"ishalftheformulatosuccessinthebovinestockmarket.Tobeconsideredagreatinvestoryoumustalsofollowthi......
  • SPOJ PHRASES Relevant Phrases of Annihilation
    DescriptionYouaretheKingofByteland.Youragentshavejustinterceptedabatchofencryptedenemymessagesconcerningthedateoftheplannedattackon......
  • POJ 1035 Spell checker
    DescriptionYou,asamemberofadevelopmentteamforanewspellcheckingprogram,aretowriteamodulethatwillcheckthecorrectnessofgivenword......
  • POJ 2774 Long Long Message
    DescriptionThelittlecatismajoringinphysicsinthecapitalofByterland.Apieceofsadnewscomestohimthesedays:hismotherisgettin......
  • POJ 1226 Substrings
    DescriptionYouaregivenanumberofcase-sensitivestringsofalphabeticcharacters,findthelargeststringX,suchthateitherX,oritsinversecan......
  • POJ 3420 Quad Tiling
    DescriptionTiredofthe TriTiling gamefinally,Michaelturnstoamorechallengeablegame,QuadTiling:Inhowmanywayscanyoutilea4× N (1≤......