BJ模拟:Bash Plays with Functions

f0(x)=p|x[pxp] f 0 ( x ) = ∑ p | x [ p ⊥ x p ]

fr(x)=p|xfr1(p) f r ( x ) = ∑ p | x f r − 1 ( p )

q q 组询问,每次给定r,n,求 fr(n) f r ( n )

题解:
水题。
首先观察到 f0(x)=2ω(x) f 0 ( x ) = 2 ω ( x ) ,这是典型的积性函数,积性函数的狄利克雷卷积也是积性函数,所以值只与 fr(pk) f r ( p k ) 有关。 注意这个函数值与具体的 p p 无关,而klogn,所以直接预处理出来即可。
对于每个 n n 可用pollardrho分解,不过这题 n n 只给到了1e6,直接预处理最小质因数就行了。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int RLEN=1<<18|1;
inline char nc() {
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
    char ch=nc(); int i=0,f=1;
    while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
    while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
    return i*f;
}

const int N=1e6+50,LIM=20,mod=1e9+7;
inline int add(int x,int y) {return (x+y>=mod) ? (x+y-mod) : (x+y);}
inline int dec(int x,int y) {return (x-y<0) ? (x-y+mod) : (x-y);}
inline int mul(int x,int y) {return (LL)x*y%mod;}
int f[N][LIM], s[N][LIM];
int npr[N],pr[N],mnpr[N],pt;
inline void sieve() {
    for(int i=2;i<N;i++) {
        if(!npr[i]) pr[++pt]=i, mnpr[i]=i;
        for(int j=1;j<=pt;j++) {
            LL k=(LL)i*pr[j];
            if(k>=N) break;
            npr[k]=1; mnpr[k]=pr[j];
            if(!(i%pr[j])) break;
        }
    }
}
int main() {
    f[0][0]=s[0][0]=1;
    for(int i=1;i<LIM;i++) f[0][i]=2, s[0][i]=add(s[0][i-1],f[0][i]);
    for(int i=1;i<N;i++) {
        f[i][0]=s[i][0]=1;
        for(int j=1;j<LIM;j++)
            f[i][j]=s[i-1][j], s[i][j]=add(f[i][j],s[i][j-1]);
    }       
    sieve();
    for(int q=rd();q;q--) {
        int r=rd(), n=rd(), rs=1;
        while(n!=1) {
            int x=mnpr[n], c=0;
            while(!(n%x)) ++c, n/=x;
            rs=mul(rs,f[r][c]);
        }
        printf("%d\n",rs);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值