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

题目:

题解:

$f_0(n) = 2^{n的不同质因子的个数}$

$ f_r(n) = \sum_{d|n}f_{r-1}(d)$

$f_0$是积性函数 , $f_r = f_0 * Id^r (1) $也是积性函数 , 所以只需要求$f_r(p^k)$就行了

$f_r(p^k)$与p无关 , $f_0(p^k)$=1+(k!=0) , $f_r(p^k)$=$\sum_{0<=i<=k}$ $ f_{r-1}(p^i)$

先递推出所有 (r,k) 的函数值, 每个询问只要分解质因数即可

时间复杂度: O((r + q) logn)

代码如下:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll; const int N=1e6+;
const int M=;
const int mod=1e9+;
int q,r,n,tot;
int prime[N],vis[N];
ll f[N][];
inline int read()
{
char ch=getchar();
int s=,f=;
while (ch<''||ch>'') {if (ch=='-') f=-;ch=getchar();}
while (ch>=''&&ch<='') {s=(s<<)+(s<<)+ch-'';ch=getchar();}
return s*f;
}
void get_prime()
{
for (int i=;i<=N;i++)
{
if (!vis[i]) prime[++tot]=i;
for (int j=;j<=tot&&prime[j]*i<=N;j++)
{
vis[prime[j]*i]=;
if (i%prime[j]==) break;
}
}
}
void pre()
{
f[][]=;
for (int i=;i<=M;i++) f[][i]=;
for (int i=;i<=N;i++)
{
ll sum=;
for (int j=;j<=M;j++)
{
sum+=f[i-][j];
f[i][j]=(f[i][j]+sum)%mod;
}
}
}
int main()
{
get_prime();
pre();
q=read();
while (q--)
{
r=read();n=read();
ll ans=;
for (int i=;i<=tot&&prime[i]<=sqrt(n);i++)
{
if (n%prime[i]) continue;
int num=;
while (n%prime[i]==) n/=prime[i],num++;
ans=1ll*ans*f[r][num]%mod;
}
if (n>) ans=1ll*ans*f[r][]%mod;
printf("%I64d\n",ans);
}
return ;
}

[Codeforces 757E] Bash Plays with Functions (数论)的更多相关文章

  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. 【codeforces 757E】Bash Plays with Functions

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

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

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

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

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

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

  8. CF757E Bash Plays with Functions

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

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

随机推荐

  1. 浅析Mysql InnoDB存储引擎事务原理

    浅析Mysql InnoDB存储引擎事务原理 大神:http://blog.csdn.net/tangkund3218/article/details/47904021

  2. Android技术归档

    各位小伙伴们.以后小巫的一些开源码都会上传到github中,所以欢迎大家Follow https://github.com/devilWwj 基于眼下我基本的技术领域在Android上,以后关于And ...

  3. Git 时间,将代码托管到GitHub 上

    第一步:在github上创建一个项目,选择所属类型.会自动生成下面的文件. 第二步:使用安卓创建项目 第三步:使用git bash 进入项目目录,通过指令clone到本地 克隆完成后会出现下面的内容 ...

  4. (转载)RecyclerView之ItemDecoration由浅入深

    RecyclerView之ItemDecoration由浅入深 作者 小武站台 关注 2016.09.19 18:20 字数 1155 阅读 10480评论 15喜欢 91赞赏 3 译文的GitHub ...

  5. Servlet学习(二)——ServletContext对象

    1.什么是ServletContext对象 ServletContext代表是一个web应用的环境(上下文)对象,ServletContext对象内部封装是该web应用的信息,一个web应用只有一个S ...

  6. 2,HTTP请求应答返回码

    200 OK 请求成功,一般用于Get和Post请求 300 多种选择.请求的资源可包括多个位置,响应的返回一个资源特征与地址的列表用于浏览器(client)选择 Multiple Choices 3 ...

  7. http状态码304

    服务器对客户端返回HTTP/1.1 304  意思是服务端告诉客户端 我的的缓存没有改变你不需要来取了,就用你自己本地的吧! 浏览器的三种缓存协商机制: if-modified-since (基于最后 ...

  8. 路飞学城Python-Day12(practise)

    # 函数基础# 1.写函数,计算传入数字参数的和(动态传参)# def sum_num(x,y):# return x+y# print(sum_num(1,2))# 2.写函数,用户传入修改的文件名 ...

  9. 关于wdsl

    WSDL元素 WSDL元素基于XML语法描述了与服务进行交互的基本元素: Type(消息类型):数据类型定义的容器,它使用某种类型系统(如XSD). Message(消息):通信数据的抽象类型化定义, ...

  10. php xml 的基本操作类

    class xmlMessage{ protected $doc; protected $rootKey; public function __construct() { $this->doc ...