大意: 定义函数$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. SQLSTATE[HY000] [2002] Connection refused

    //域名绑定到模块 '__domain__' => [ 'admin' => 'admin', 'post' => 'api', 'user' => 'index', 'www ...

  2. 访问H2数据库的SpringBoot工程

    JDK:1.8.0_212 IDE:STS4(Spring Tool Suit4 Version: 4.3.2.RELEASE) 工程下载:https://files.cnblogs.com/file ...

  3. 码云上webide怎么提交

    修改后想提交,它会提示:“暂存文件后才能提交”, 我拿放大镜找遍了整个界面也没找到“暂存”按钮, 原来,文件旁边那个+号就是暂存,好歹鼠标方式去之后给个tip,服了. 点一下这个加号,提交按钮就可用了 ...

  4. Java快排

    package quickSort; /** * 快速排序 * @author root * */ public class QuickSort { static int[] data = {0,2, ...

  5. dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib

    dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib Table of Contents 1. 启动时报错 ...

  6. springboot2.0---控制台打印Mybatis的SQL记录

    题记:每次使用mybatis出错,都不知道sql原因,debug也不出结果,索性将其打印出来,更加容易排错. 亲测有效,只需要将下面的logback.xml放置在resource目录下即可打印. 方式 ...

  7. python programming作业10(仍有一点点小bug)

    # -*- coding: utf-8 -*- import os import platform import sys from PyQt5.QtCore import * from PyQt5.Q ...

  8. 阿里巴巴 fastjson-1.2.12.jar json解析异常java.lang.ClassFormatError: Invalid method Code length 66865 in class file com/alibaba/fastjson/serializer/ASMSerializer_6_UserKdlb

    承接上篇:fastjson反序列化LocalDateTime失败的问题java.time.format.DateTimeParseException: Text '2019-05-24 13:52:1 ...

  9. 移动端1px 边框

    伪类+ transform .border_1px:before{ content: ''; position: absolute; top: 0; height: 1px; width: 100%; ...

  10. 03 vue项目结构

    上一篇已介绍根据vue-cli创建项目,本篇介绍根据vue-cli官方脚手架创建的项目的项目结构. 一.图看结构 build  [webpack配置]         webpack相关配置,都已经配 ...