题目: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. Linux vi替换字符串

    1. 基本的替换 :s/vivian/sky/ 替换当前行第一个 vivian 为 sky :s/vivian/sky/g 替换当前行所有 vivian 为 sky :n,$s/vivian/sky/ ...

  2. hdu 1689 求奇环bfs关键是层次图

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> usin ...

  3. Contest Hunter #46 T1 磁力块 [花式暴力]

    将所有石头按距离远近排序,将所有取到的时候扔进堆里维护最大磁力强度. 贪心,每次用强度最强的磁石尝试吸引地上的石头,扫完区间以后,这块石头就再也不会用到了. 在此基础上可以做些小优化,比如说优化未取石 ...

  4. msp430入门编程24

    msp430中C语言的扩展--段的使用 msp430入门学习 msp430入门编程

  5. CDN是什么与CDN加速的原理

    CDN是什么 CDN全称:Content Delivery Network或Content Ddistribute Network,即内容分发网络 CDN设计思路 避让:尽可能避开互联网上有可能影响数 ...

  6. 转 Linux里设置环境变量的方法(export PATH)

    1.动态库路径的设置 Linux下调用动态库和windows不一样.linux 可执行程序是靠配置文件去读取路径的,因此有些时候需要设置路径 具体操作如下export LD_LIBRARY_PATH= ...

  7. 使用mysql-connector-java.jar连接MySql时出现:Error while retrieving metadata for procedure columns: java.sql.SQLException: Parameter/Column name pattern can not be NULL or empty.

    错误如下: 程序实现的功能是调用一个存储过程,但是不认这个存储过程的参数. 原因是版本太高了,由于使用的是6.0.6版本的,改成5.1.38即可. POM配置如下: <!-- mysql-con ...

  8. CheckStyle: 解决Unicode导致LineLength出错的问题

    在checkstyle.xml中,加上如下代码: <?xml version="1.0" encoding="UTF-8"?> <module ...

  9. Centos 5.11 samba

    1.使用yum安装samba,添加samba user yum install samba samba-client samba-swatuseradd smbuser -m             ...

  10. vue - 官方 - 上手

    Vue和其它框架一样,有用CDN或本地JavaScript框架,国内我推荐 bootstrap cdn. 为什么很多人选择CDN呢? CDN:内容分发网络(不同区域不同服务器,更快),减少本地服务器压 ...