大意: 定义函数$f_r(n)$, $f_0(n)$为pq=n且gcd(p,q)=1的有序对(p,q)个数.

$r \ge 1$时, $f_r(n)=\sum\limits_{uv=n}\frac{f_{r-1}(u)+f_{r-1}(v)}{2}$.

$q$组询问, 求$f_r(n)$的值模1e9+7.

显然可以得到$f_0(n)=2^{\omega(n)}$, 是积性函数.

所以$f_r=f_{r-1}*1$也为积性函数, 然后积性函数$dp$即可.

问题就转化为对每个素数$p$, 求$dp[p][r][k]=f_r(p^k)$.

$dp[p][r][k]=\sum\limits_{x=0}^k dp[p][r-1][x]$.

而$dp[p][0][k]=1$, 所以每个素数贡献相同, 只需要$dp$一次即可.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 1e6+10;
int dp[N][22], sum[N][22], mi[N]; int main() {
dp[0][0]=sum[0][0]=1;
REP(i,1,21) sum[0][i]=sum[0][i-1]+(dp[0][i]=2);
REP(i,1,N-1) {
dp[i][0]=sum[i][0]=1;
REP(j,1,21) sum[i][j]=(sum[i][j-1]+(dp[i][j]=sum[i-1][j]))%P;
}
REP(i,1,N-1) mi[i] = i;
REP(i,2,N-1) if (mi[i]==i) {
for (int j=i; j<N; j+=i) mi[j]=min(mi[j],i);
}
int q;
scanf("%d", &q);
while (q--) {
int r, n;
scanf("%d%d", &r, &n);
int ans = 1;
while (n!=1) {
int t = mi[n], k = 0;
while (n%t==0) n/=t, ++k;
ans = (ll)ans*dp[r][k]%P;
}
printf("%d\n", ans);
}
}

Bash Plays with Functions CodeForces - 757E (积性函数dp)的更多相关文章

  1. codeforces757E. Bash Plays with Functions(狄利克雷卷积 积性函数)

    http://codeforces.com/contest/757/problem/E 题意 Sol 非常骚的一道题 首先把给的式子化一下,设$u = d$,那么$v = n / d$ $$f_r(n ...

  2. Makoto and a Blackboard CodeForces - 1097D (积性函数dp)

    大意: 初始一个数字$n$, 每次操作随机变为$n$的一个因子, 求$k$次操作后的期望值. 设$n$经过$k$次操作后期望为$f_k(n)$. 就有$f_0(n)=n$, $f_k(n)=\frac ...

  3. Codeforces E. Bash Plays with Functions(积性函数DP)

    链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...

  4. Codeforces757E.Bash Plays With Functions(积性函数 DP)

    题目链接 \(Description\) q次询问,每次给定r,n,求\(F_r(n)\). \[ f_0(n)=\sum_{u\times v=n}[(u,v)=1]\\ f_{r+1}(n)=\s ...

  5. D. Makoto and a Blackboard(积性函数+DP)

    题目链接:http://codeforces.com/contest/1097/problem/D 题目大意:给你n和k,每一次可以选取n的因子代替n,然后问你k次操作之后,每个因子的期望. 具体思路 ...

  6. Problem : 这个题如果不是签到题 Asm.Def就女装(积性函数dp

    https://oj.neu.edu.cn/problem/1460 思路:若n=(p1^a1)*(p2^a2)...(pn^an),则f(n,0)=a1*a2*...*an,显然f(n,0)是积性函 ...

  7. CF 757E Bash Plays with Functions——积性函数+dp+质因数分解

    题目:http://codeforces.com/contest/757/problem/E f0[n]=2^m,其中m是n的质因子个数(种类数).大概是一种质因数只能放在 d 或 n/d 两者之一. ...

  8. CF 757 E Bash Plays with Functions —— 积性函数与质因数分解

    题目:http://codeforces.com/contest/757/problem/E 首先,f0(n)=2m,其中 m 是 n 的质因数的种类数: 而且 因为这个函数和1卷积,所以是一个积性函 ...

  9. 【codeforces 757E】Bash Plays with Functions

    [题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...

随机推荐

  1. sql把一段时间分割成周,月,季度,年的时间段

    --本周 select TO_CHAR(CREATE_DATE ,'yyyy-MM-dd')as NEW_DATE , TO_CHAR(trunc(CREATE_DATE, ,'yyyy-MM-dd' ...

  2. 阿里云maven镜像

    <mirror> <id>nexus-aliyun</id> <mirrorOf>*</mirrorOf> <name>Nexu ...

  3. 发送http请求和https请求的工具类

    package com.haiyisoft.cAssistant.utils; import java.io.IOException;import java.util.ArrayList; impor ...

  4. logstash的index值可以为中文

    logstash中的 output中 有index属性,表示在elk中的主键标识. 在实际应用中,index的值不能为大写字母,可以是小写字母.数字.下划线.中文. 这里重点强调index为中文时,注 ...

  5. Nginx服务应用

    虚拟主机 基于域名的虚拟主机 所谓基于域名的虚拟主机,意思就是通过不同的域名区分不同的虚拟主机,基于域名的虚拟主机是企业应用最广的虚拟主机类型,几乎所有对外提供服务的网站都是使用基于域名的虚拟主机 基 ...

  6. javascript之Math对象

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. NDK的环境配置

    http://www.androiddevtools.cn/ 下载NDK, 最新版本. 解压压缩包,如解压后文件夹名为如android-ndk-r13,放在指定的位置 配置环境变量: 系统环境path ...

  8. 五十八:Flask.Cookie之flask设置和删除cookie

    1.设置cookie:在flask.Response对象上,使用set_cookie('cookie名', 'cookie值')设置cookie set_cookie源码 key:cookie名val ...

  9. 五十五:WTForms表单验证之渲染模板

    此功能看似强大,实则鸡肋 from wtforms import Form, StringField, BooleanField, SelectFieldfrom wtforms.validators ...

  10. JS事件中级 --- 拖拽

    http://bbs.zhinengshe.com/thread-1200-1-1.html 要求:实现div块的拖拽 原理:拖拽过程中鼠标点和div块的相对位置保持不变. 需要理解三点: 1. 为什 ...