题目:http://codeforces.com/contest/757/problem/E

首先,f0(n)=2m,其中 m 是 n 的质因数的种类数;

而且

因为这个函数和1卷积,所以是一个积性函数,就可以每个质因子单独考虑;

而 f0(pq) = 2,对于每个质因子都一样!

所以可以 DP 预处理

fr(n) = fr(p1e1) * fr(p2e2) * ... * fr(pqeq)fr(n) = dp[r][e1] * dp[r][e2] * ... * dp[r][eq]

学到了质因数分解的新姿势!先预处理所有数的最小质因子,然后分解时直接除最小质因子,则复杂度就是 logn!

总之,真是一道好题!

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int const xn=1e6+,mod=1e9+;
int q,r,n,dp[xn][],mnp[xn];
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=(ret<<)+(ret<<)+ch-'',ch=getchar();
return f?ret:-ret;
}
int upt(ll x){while(x>=mod)x-=mod; while(x<)x+=mod; return x;}
void init()
{
int mx=1e6; mnp[]=;
for(int i=;i<=mx;i++)
if(!mnp[i])for(int j=i;j<=mx;j+=i)mnp[j]=i;//
dp[][]=;
for(int i=;i<=;i++)dp[][i]=;
for(int i=,s=;i<=mx;i++,s=)
for(int j=;j<=;j++)s=upt(s+dp[i-][j]),dp[i][j]=s;
}
int div(int x)
{
int ans=;
while(x!=)
{
int i=mnp[x],cnt=;
while(x%i==)cnt++,x/=i;
ans=((ll)ans*dp[r][cnt])%mod;
}
return ans;
}
int main()
{
q=rd(); init();
while(q--)
{
r=rd(); n=rd();
printf("%d\n",div(n));
}
return ;
}

CF 757 E Bash Plays with Functions —— 积性函数与质因数分解的更多相关文章

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

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

  2. 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 ...

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

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

  4. 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 ...

  5. 【codeforces 757E】Bash Plays with Functions

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

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

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

  7. 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 ...

  8. [Codeforces 757E] Bash Plays with Functions (数论)

    题目链接: http://codeforces.com/contest/757/problem/E?csrf_token=f6c272cce871728ac1c239c34006ae90 题目: 题解 ...

  9. CF757E Bash Plays with Functions

    题解 q<=1e6,询问非常多.而n,r也很大,必须要预处理所有的答案,询问的时候,能比较快速地查询. 离线也是没有什么意义的,因为必须递推. 先翻译$f_0(n)$ $f_0(n)=\sum_ ...

随机推荐

  1. 【2018 Multi-University Training Contest 1】

    01:https://www.cnblogs.com/myx12345/p/9362221.html 02:https://www.cnblogs.com/myx12345/p/9382267.htm ...

  2. gerrit ssh 登陆设置

    [root@web ~]# cat ~/.ssh/config Host gerrit User deploy-gerrit Port Hostname gerrit.demo.com Identit ...

  3. windows7 下安装使用memcached(二)

    Memcached 安装使用 本地环境:Windows7 64位web环境:wamp集成环境,php版本:PHP Version 7.1.17 学习参考网站: RUNOOB.COM官网  http:/ ...

  4. poj——3177Redundant Paths

    poj——3177Redundant Paths      洛谷—— P2860 [USACO06JAN]冗余路径Redundant Paths Time Limit: 1000MS   Memory ...

  5. maven pom.xml文件介绍

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  6. centos、mac的grafana安装和简单使用

    1.安装: 参考官方文档安装说明:https://grafana.com/grafana/download Redhat & Centos(64 Bit): wget https://s3-u ...

  7. python实现接口自动化

    一.总述 Postman:功能强大,界面好看响应格式自主选择,缺点支持的协议单一且不能数据分离,比较麻烦的还有不是所有的公司都能上谷歌SoupUI:支持多协议(http\soup\rest等),能实现 ...

  8. Codeforces Round #316 (Div. 2) C. Replacement

    题意:给定一个字符串,里面有各种小写字母和' . ' ,无论是什么字母,都是一样的,假设遇到' . . ' ,就要合并成一个' .',有m个询问,每次都在字符串某个位置上将原来的字符改成题目给的字符, ...

  9. Linux —— 查找与替换

    Linux —— 查找与替换 文本查找: grep, egrep, fgrep        grep:根据基本正则表达式定义的模式搜索文档,并将符合模式的文本行显示出来        注意:搜索时属 ...

  10. Javascript调试命令

    Javascript调试命令——你只会Console.log() ? Console 对象提供对浏览器控制台的接入(如:Firefox 的 Web Console).不同浏览器上它的工作方式是不一样的 ...