题目链接

\(Description\)

  q次询问,每次给定r,n,求\(F_r(n)\)。

\[ f_0(n)=\sum_{u\times v=n}[(u,v)=1]\\
f_{r+1}(n)=\sum_{u\times v=n}\frac{f_r(u)+f_r(v)}{2}\]

\(Solution\)

  首先将\(f_r\)的式子化为

\[f_{r+1}(n)=\sum_{d|n}f_r(d)
\]

  即\(f_{r+1}(n)\)为\(f_r(n)\)与\(g(n)=1\)的狄利克雷卷积。

  因为n的所有质因子之间对\(f_0(n)\)的贡献是独立的,所以显然\(f_0(n)\)为积性函数(为什么我还是不懂。。),那么\(f_r(n)\)也为积性函数。

  于是可以对每个质因子单独计算,这样狄利克雷卷积就可以化成求和

\[f_{r+1}(p^k)=\sum_{i=0}^kf_r(p^i)
\]

  (\(p^k\)的所有因子即\(p^i,i=0,1,\ldots,k\))

  同时可以发现\(f_0(p^k)=[k\neq 0]+1\),即\(f_0(p^k)\)的值与因子p无关,只与次数有关。

  那么DP,用\(dp[i][j]\)表示\(f_i(p^j)\),则\(dp[i][j]=\sum_{k=0}^jdp[i-1][k]\)。

  询问时对\(n\)分解质因数即可。

#include<cmath>
#include<cstdio>
#include<cctype>
#define gc() (SS==TT&&(TT=(SS=IN)+fread(IN,1,MAXIN,stdin),SS==TT)?EOF:*SS++)
const int N=1e6+3,M=21,mod=1e9+7,MAXIN=1<<18; int r,n,f[N+3][21],Primes[100000],cnt;
char IN[MAXIN],*SS=IN,*TT=IN;
bool Not_Prime[N+3]; inline int read()
{
int now=0,f=1;register char c=gc();
for(;!isdigit(c);c=gc()) if(c=='-') f=-1;
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now*f;
}
#define Mod(a) (a>=mod)?a-=mod:0
void Init()
{
// Not_Prime[1]=1;
for(int i=2;i<N;++i)
{
if(!Not_Prime[i]) Primes[++cnt]=i;
for(int j=1;j<=cnt&&Primes[j]*i<N;++j)
{
Not_Prime[i*Primes[j]]=1;
if(!(i%Primes[j])) break;
}
}
f[0][0]=1;//f_r(p^0)=1
for(int i=1;i<M;++i) f[0][i]=2;
for(int sum=0,i=1;i<N;++i,sum=0)
for(int j=0;j<M;++j)
{
sum+=f[i-1][j], Mod(sum);
f[i][j]+=sum, Mod(f[i][j]);
}
}
int Solve(int r,int n)
{
int ans=1,m=sqrt(n+0.5);
for(int i=1;i<=cnt&&Primes[i]<=m;++i)
{
if(n%Primes[i]) continue;
int t=0;
while(!(n%Primes[i])) n/=Primes[i],++t;
ans=1LL*ans*f[r][t]%mod;
}
if(n>1) ans=1LL*ans*f[r][1]%mod;//本身是个质数
return ans;
} int main()
{
//#ifndef ONLINE_JUDGE
// freopen("757.in","r",stdin);
//#endif Init();
int t=read(),r,n;
while(t--)
r=read(),n=read(),printf("%d\n",Solve(r,n));
return 0;
}

Codeforces757E.Bash Plays With Functions(积性函数 DP)的更多相关文章

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

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

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

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

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

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

  4. Bash Plays with Functions CodeForces - 757E (积性函数dp)

    大意: 定义函数$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 ...

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

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

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

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

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

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

  8. 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)是积性函 ...

  9. Codeforces 757 E Bash Plays with Functions

    Discription Bash got tired on his journey to become the greatest Pokemon master. So he decides to ta ...

随机推荐

  1. 【CTF WEB】ISCC 2016 web 2题记录

      偶然看到的比赛,我等渣渣跟风做两题,剩下的题目工作太忙没有时间继续做. 第1题 sql注入: 题目知识 考察sql注入知识,题目地址:http://101.200.145.44/web1//ind ...

  2. oracle ip 改为 机器名

    1 hosts文件 添加                   ip  机器名   这一行 2 修改listner.ora 和tnsora.ora ip改为机器名 3 重启服务

  3. python httplib和urllib的性能比较

    httplib代码: urlParseResult = urlparse(url) host = urlParseResult.hostname path = urlParseResult.path ...

  4. zabbix系列(九)zabbix3.0实现自动触发zabbix-agent端shell脚本任务

    zabbix实现自动触发远程脚本执行命令 Zabbix触发器(trigger)达到阀值后会有动作(action)执行:发送告警信息或执行远程命令 环境 Server:基于centos6.5 final ...

  5. dispatchers 设置

    Oracle连接方式(dispatchers 设置) oracle 响应客户端请求有两种方式: 1 专有连接:用一个服务器进程响应一个客户端请求 2 共享连接:用一个分派器(dispatcher)响应 ...

  6. MyEclipse 2017 ci6 安装反编译插件(本人自己摸索的方法,亲测可行)

    注: 本文来源于:Smile_Miracle 的< MyEclipse 2017 ci6 安装反编译插件(本人自己摸索的方法,亲测可行) > 第一步:关闭ME,去一下地址下载jad的反编译 ...

  7. 【hadoop】python通过hdfs模块读hdfs数据

    hdfs官网:http://hdfscli.readthedocs.io/en/latest/api.html 一个非常好的博客:http://blog.csdn.net/gamer_gyt/arti ...

  8. Codeforces 448C Painting Fence(分治法)

    题目链接:http://codeforces.com/contest/448/problem/C 题目大意:n个1* a [ i ] 的木板,把他们立起来,变成每个木板宽为1长为 a [ i ] 的栅 ...

  9. js获取当前有效样式

      js获取有效样式   节点.currentStyle["属性名"]        兼容ie方法(只有ie有效) getcomputedStyle(节点)["属性名&q ...

  10. SpringMVC MongoDB之“基本文档查询(Query、BasicQuery)”

    一.简介 spring Data  MongoDB提供了org.springframework.data.mongodb.core.MongoTemplate对MongoDB的CRUD的操作,上一篇我 ...