题目链接: 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. APP热更新方案(转)

    本文转载自[http://creator.cnblogs.com/] 博客地址:Zealot Yin 为什么要做热更新 当一个App发布之后,突然发现了一个严重bug需要进行紧急修复,这时候公司各方就 ...

  2. intellij idea 打开两个 terminal

    intellij idea 打开两个  terminal alt+f12可以打开terminal,在terminal窗口左侧点击绿色的加号,就可以又打开一个terminal,用tab标签展示:

  3. Ruby中写换行

    Ruby中写换行 print("Hello,\nRuby\n!\n") print("Hello, Ruby ! ") 这两个竟然是一样的:就是说,可以直接回车 ...

  4. Go语言核心之美 1.1-命名篇

    命名篇 1.Go的函数.变量.常量.自己定义类型.包(Package)的命名方式遵循以下规则: 1)首字符能够是随意的Unicode字符或者下划线 2)剩余字符能够是Unicode字符.下划线.数字 ...

  5. leetcode第一刷_Add Binary

    二进制相加,本质上就是大整数加法,有关大整数加法我的舍友教过我一个非常好的方法,先用一个int数组保存结果,将两个数相应位置相加,所有加完后.再统一处理进位的问题.这种方法相同适用于大整数的乘法. 这 ...

  6. GCC 优化选项 -O1 -O2 -O3 -OS 优先级,-FOMIT-FRAME-POINTER(O3的优化很小,只增加了几条优化而已)

    四种编译优化类型的解释: `-O ' `-O1 '                 Optimize.      Optimizing   compilation   takes   somewhat ...

  7. HTML5客户端数据存储机制Web Storage和Web SQL Database

    引言 html5本地存储可以选择两种方式,一种是本地存储,一种是sqlite. 比如开发html5的购物车功能,就可以考虑选择其中之一,进行本地存储与操作. 又或者保存用户登录信息,可以使用local ...

  8. JavaScript中Number常用属性和方法

    title: JavaScript中Number常用属性和方法 toc: false date: 2018-10-13 12:31:42 Number.MAX_VALUE--1.79769313486 ...

  9. NPInter数据集的奇葩标号的出坑秘籍

    这篇恐怕是有始以来命名最无奈标题了.需要写一下攻略. 业内人士都熟知NPInter,但是该数据库一直以来访问受限.不过终于能访问得到数据集. 但是蛋疼的是2.0的数据库id的命名方法实在奇葩,想了很多 ...

  10. 线程状态与tcb、线程的生命周期

    struct tcb { u32_t status; struct reg_context thread_context; void *stack; struct thread_info thread ...