POJ 1845-Sumdiv(厉害了这个题)
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).
题意很简单a的b次方的因数和对9901取模;
这个题题意很简单,但是看数据量加操作肯定超时,涵盖知识量极多。
1.快速幂:递归求解指数运算。
指数过大无法运算,虽然不知道他们是怎么做的,估计跟这个差不多。
PS
typedef long long LL;
LL power(int a,int b){
LL ans=1;
while(b){
if(p&1) ans=ans*a; /判断是否为奇数(可以%2,按位或&可能快一点)
a=a*a;
b>>=1;
}
return ans;
以2 ^ 8 和2 ^ 9为例,
a=2,b=8;
b是偶数,进行下一步
a=22=4;
b=4;
b是偶数,进行下一步
a=44=16:
b=2;
next
a=1616=256
b=1;
next
b是奇数;
ans=1a=256;
只用了log2n次的乘法;
2.A^B的所有约数之和为:
sum = [1+p1+p12+…+p1 (a1*B)] * [1+p2+p22+…+p2(a2*B)] … [1+pn+pn2+…+pn(an*B)].
3.埃氏筛法
直接板子(这里我用了近似的思想,当时还没明白这个方法)
int a[maxx];
int b[maxx+1];
int gg(int n)
{
int p=0;//记录素数个数
for(int i=0;i<n+1;i++)b[i]=1;
b[0]=0;
b[1]=0;
//准备完毕
for(int i=2;i<=n;i++){
if(b[i]){
a[p++]=i;//记录素数和个数
for(int j=2*i;j<=n;j+=i)b[j]=0;//剔除倍数
}
}
return p;//返回素数个数
}
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#define MOD 9901
using namespace std;
int a,b,z;
int p[10000]; //质数
int p_n[10000];//质数个数
void Zhi()//质数打表,求小于根号a的质数
{
int t = a;
for (int i=2; i*i<=a; i++)//开方运算比乘法用时间长
{
if (t%i==0)
{
p[z]=i;
p_n[z]=1;
t/=i;
while (t%i==0)
{
p_n[z]++;
t/=i;
}
z++;
}
if (t==1) break;
if (i!=2)
i++;//2.3.5.7.9...
}
if (t!=1)//本身就是质数
{
p[z]=t;
p_n[z]=1;
z++;
}
}
int Mi(int a, int b)//快速幂
{
int res = 1;
a%=MOD;
while(b)
{
if (b&1) res = (res * a)%MOD;
a=(a*a)%MOD;
b>>=1;
}
return res;
}
int Ys(int p , int n)//递归求等比系数
{
if (n==0) return 1;
if (n%2==1)
return ((Mi(p,n/2+1)+1) * Ys(p,n/2))%MOD;
else
return ((1+Mi(p,n/2+1)) * Ys(p,n/2-1) + Mi(p,n/2))%MOD;
}
int main()
{
while (scanf("%d%d",&a,&b)!=EOF)
{
z=0;//质数个数
Zhi();
int ans = 1;
for (int i=0; i<z; i++)
{
ans=(ans*Ys(p[i],p_n[i]*b))%MOD;
}
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 约数和定理
Sumdiv 题目连接: http://poj.org/problem?id=1845 Description Consider two natural numbers A and B. Let S ...
- 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,求a^b的所有自然数因子的和模上9901 (0 <= a,b <= 50000000 ...
- POJ 1845 Sumdiv#质因数分解+二分
题目链接:http://poj.org/problem?id=1845 关于质因数分解,模板见:http://www.cnblogs.com/atmacmer/p/5285810.html 二分法思想 ...
- POJ 1845 Sumdiv [素数分解 快速幂取模 二分求和等比数列]
传送门:http://poj.org/problem?id=1845 大致题意: 求A^B的所有约数(即因子)之和,并对其取模 9901再输出. 解题基础: 1) 整数的唯一分解定理: 任意正整数都有 ...
- POJ 1845 Sumdiv
快速幂+等比数列求和.... Sumdiv Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12599 Accepted: 305 ...
- 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 ...
随机推荐
- Vulnhub JIS-CTF-VulnUpload靶机渗透
配置问题解决 参考我的这篇文章https://www.cnblogs.com/A1oe/p/12571032.html更改网卡配置文件进行解决. 信息搜集 找到靶机 nmap -sP 192.168. ...
- MTK Android Driver :Lcm
MTK Android Driver :lcm 1.怎样新建一个LCD驱动 LCD模组主要包括LCD显示屏和驱动IC.比如LF040DNYB16a模组的驱动IC型号为NT35510.要在MTK6577 ...
- R语言—如何安装Github包的解决方法,亲测有效
R语言—如何安装Github包的解决方法,亲测有效 准备安装材料: R包-REmap GitHub下载地址:https://github.com/lchiffon/REmap R包-baidumap ...
- Django 已生成数据时怎么查询数据库
数据库已写好时,怎样查询数据库 1.输入命令:python manage.py inspectdb > model1.py 注:>重定向 到model1.py
- 最全的中文NLP资源库,你确定不来看一下吗?
最全的中文NLP资源库,你确定不来看一下吗? 22/100 发布文章 qq_39248703 hello,小伙伴们大家好,今天给大家分享NLP资源库,可以说是最全的资源库了,很多包非常有趣,值得收藏, ...
- Struts2-学习笔记系列(12)-set集合
3.1编写类型转换器 只需实现 converFromString方法 public class UserConvert extends StrutsTypeConverter { @Override ...
- 2019-08-01【机器学习】有监督学习之分类 KNN,决策树,Nbayes算法实例 (人体运动状态信息评级)
样本: 使用的算法: 代码: import numpy as np import pandas as pd import datetime from sklearn.impute import Sim ...
- Git应用详解第九讲:Git cherry-pick与Git rebase
前言 前情提要:Git应用详解第八讲:Git标签.别名与Git gc 这一节主要介绍git cherry-pick与git rebase的原理及使用. 一.Git cherry-pick Git ch ...
- delphi中DateTimePicker控件同时输入日期和时间
将DateTimePicker的Format属性中加入日期格式设成 'yyyy-MM-dd HH:mm',注意大小写 , 将kind设置为dtkTime即可,可以在每次Form onShow时将Dat ...
- 爬取腾讯网的热点新闻文章 并进行词频统计(Python爬虫+词频统计)
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:一棵程序树 PS:如有需要Python学习资料的小伙伴可以加点击下方链 ...