当前位置:网站首页>(Codeforce 757)E. Bash Plays with Functions(积性函数)
(Codeforce 757)E. Bash Plays with Functions(积性函数)
2022-08-01 04:47:00 【AC__dream】
题目:
样例输入:
5
0 30
1 25
3 65
2 5
4 48
样例输出:
8
5
25
4
630
题意:
我们先来分析r=0的情况,假如我们现在求f0(n),n=p1^a1*p2^a2*……*pm^am
那么f0(n)就等于2^m,这是显然的,因为我们假设p=p1^b1*p2^b2*……*pm^bm,那么对于任意的bi(1<=i<=m)都有bi=0或者bi=ai,要不然不会存在q使得p*q=n且gcd(p,q)=1,那么我们就不难发现其实f0(x)是一个积性函数。假设对于n=p*q,gcd(p,q)=1,则p和q的质因子分解中不会存在相同质因子,不妨假设p有i个质因子,q有j个质因子,那么p*q就会有i+j个质因子,那么f0(pq)=2^(i+j)=2^i*2^j=f0(p)*f0(q),所以f0(x)是一个积性函数。
下面我用归纳法来证明对于任意的r都有fr(x)是一个积性函数。

我们知道对于r=0的情况f0(n)的值只与n的质因子的种类有关,而与具体的质因子无关,而r不为0的情况是由r=0的情况得到的,所以r不为0的时候与具体的质因子也不会有关系。我们上面推导了对于任意的r都有fr(x)是一个积性函数,所以我们求fr(n)时只需要看n的质因子分解情况即可,那么问题就转变为求解fr(p^i),p是一个质数,根据公式我们可以发现fr(p^i)=
,又因为与具体的质因子无关,通过上式我们可以发现只与质因子的次数有关,那么我们就可以令f[i][j]记录fi(p^j)的值 ,由于n是小于1e6的,所以质因子分解中最高次数不会超过20,这样通过O(r*20)就可以预处理出来所有的数。当r=0时,根据其定义我们可以知道f[0][1]=1,f[0][i]=2(i>1),预处理一下即可
剩下的就是对于每组询问记录一下质因子次数,直接利用积性函数性质求解了。
下面是代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
const int N=1e6+10,mod=1e9+7;
long long f[N][21];//f[i][j]表示fi(p^j)
int prime[N],tt;
bool vis[N];
void init()
{
f[0][0]=1;
for(int i=1;i<=20;i++) f[0][i]=2;
for(int i=1;i<=1000000;i++)
{
long long ans=0;
for(int j=0;j<=20;j++)
{
ans=(ans+f[i-1][j])%mod;
f[i][j]=ans;
}
}
}
int main()
{
init();
int T;
cin>>T;
while(T--)
{
int r,n;
scanf("%d%d",&r,&n);
long long ans=1;
for(int i=2;i*i<=n;i++)
{
int cnt=0;
if(n%i==0)
{
while(n%i==0)
{
n/=i;
cnt++;
}
ans=ans*f[r][cnt]%mod;
}
}
if(n>1) ans=ans*f[r][1]%mod;
printf("%lld\n",ans);
}
return 0;
}
边栏推荐
- 风险策略调优中重要的三步分析法
- 这里有110+公开的专业数据集
- Character encoding and floating point calculation precision loss problem
- [kali-information collection] enumeration - DNS enumeration: DNSenum, fierce
- RSA主要攻击方法
- lambda
- Invalid classes inferred from unique values of `y`. Expected: [0 1 2], got [1 2 3]
- MySQL-数据定义语言-DDLdatebase define language
- 【kali-信息收集】枚举——DNS枚举:DNSenum、fierce
- Simulation of Active anti-islanding-AFD Active Anti-islanding Model Based on Simulink
猜你喜欢

Software Testing Weekly (Issue 82): In fact, all those who are entangled in making choices already have the answer in their hearts, and consultation is just to get the choice that they prefer.

button remove black frame

JS new fun(); class and instance JS is based on object language Can only act as a class by writing constructors

typescript27-枚举类型呢

Unknown Bounded Array

Make your Lottie support word wrapping in text fields

MySQL4
![Valentine's Day Romantic 3D Photo Wall [with source code]](/img/a9/2c26f4f048f3c0a9a65551bc734233.png)
Valentine's Day Romantic 3D Photo Wall [with source code]

Progressive Reconstruction of Visual Structure for Image Inpainting 论文笔记

UE4 模型OnClick事件不生效的两种原因
随机推荐
Mysql中的数据类型和运算符
MLP neural network, GRNN neural network, SVM neural network and deep learning neural network compare and identify human health and non-health data
Flutter Tutorial 02 Introduction to Flutter Desktop Program Development Tutorial Run hello world (tutorial includes source code)
The maximum quantity leetcode6133. Grouping (medium)
Make your Lottie support word wrapping in text fields
这里有110+公开的专业数据集
Character encoding and floating point calculation precision loss problem
今日睡眠质量记录68分
UE4 rays flashed from mouse position detection
typescript26-字面量类型
Message Queuing Message Storage Design (Architecture Camp Module 8 Jobs)
怀念故乡的月亮
数据比对功能调研总结
云服务器下载安装mongo数据库并远程连接详细图文版本(全)
在互联网时代,有诸多「互联网+」模式的诞生
Dynamic Programming 01 Backpack
56:第五章:开发admin管理服务:9:开发【文件上传到,MongoDB的GridFS中,接口】;(把文件上传到GridFS的SOP)
typescript25 - type assertion
August 22 Promotion Ambassador Extra Reward Rules
leetcode6132. Make all elements in an array equal to zero (simple, weekly)