[Codeforces 757E] Bash Plays with Functions (数论)
题目链接: 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 (数论)的更多相关文章
- Codeforces E. Bash Plays with Functions(积性函数DP)
链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...
- CF 757E Bash Plays with Functions——积性函数+dp+质因数分解
题目:http://codeforces.com/contest/757/problem/E f0[n]=2^m,其中m是n的质因子个数(种类数).大概是一种质因数只能放在 d 或 n/d 两者之一. ...
- 【codeforces 757E】Bash Plays with Functions
[题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...
- 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 ...
- 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 ...
- codeforces757E. Bash Plays with Functions(狄利克雷卷积 积性函数)
http://codeforces.com/contest/757/problem/E 题意 Sol 非常骚的一道题 首先把给的式子化一下,设$u = d$,那么$v = n / d$ $$f_r(n ...
- CF 757 E Bash Plays with Functions —— 积性函数与质因数分解
题目:http://codeforces.com/contest/757/problem/E 首先,f0(n)=2m,其中 m 是 n 的质因数的种类数: 而且 因为这个函数和1卷积,所以是一个积性函 ...
- CF757E Bash Plays with Functions
题解 q<=1e6,询问非常多.而n,r也很大,必须要预处理所有的答案,询问的时候,能比较快速地查询. 离线也是没有什么意义的,因为必须递推. 先翻译$f_0(n)$ $f_0(n)=\sum_ ...
- 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 ...
随机推荐
- 【Oracle学习笔记】
内容主要包括: (1)三种循环及其简化 (2)游标的使用 (3)异常处理 (4)存储过程 (5)存储函数 (6)触发器 (7)其它pl/sql操作 ---------------loop循环定义变量- ...
- python微框架Bottle(http)
环境: win7系统 Python2.7 一 背景和概述 眼下项目中须要加入一个激活码功能,打算单独弄一个httpserver来写. 由于之前的游戏中已经有了一套完整的激活码生成工具和验证httpse ...
- zzulioj--1634--Happy Thanksgiving Day - A + B Problem(模拟水题)
1634: Happy Thanksgiving Day - A + B Problem Time Limit: 1 Sec Memory Limit: 128 MB Submit: 136 ...
- nyoj--236--心急的C小加(动态规划&&LIS)
心急的C小加 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 C小加有一些木棒,它们的长度和质量都已经知道,需要一个机器处理这些木棒,机器开启的时候需要耗费一个单位的时间 ...
- BZOJ 4636 (动态开节点)线段树
思路: 偷懒 懒得离散化 搞了个动态开节点的线段树 (其实是一样的--..) 注意会有a=b的情况 要判掉 //By SiriusRen #include <cstdio> #includ ...
- Linux安装(虚拟机)
** 虚拟机安装CentOS系统 以下步骤会连续给出截图,大家自行校对即可. 首先打开虚拟机,出现的界面如上一篇文章截图所示. ** 配置虚拟机 步骤: 1.点击“创建新的虚拟机” 2.选择“ ...
- <Three.js>(第三节)全景漫游
一.实验内容 通过上次实验,了解了Three.js创建场景的基本步骤.这一节,我们将通过Three.js实现全景漫游功能.如下图: 全景图是获取一个3D场景中的不同角度的图片,然后通过拼接.融合实现3 ...
- python下载网页转化成pdf
最近在学习一个网站补充一下cg基础.但是前几天网站突然访问不了了,同学推荐了waybackmachine这个网站,它定期的对网络上的页面进行缓存,但是好多图片刷不出来,很憋屈.于是网站恢复访问后决定把 ...
- CTSC2012 熟悉的文章 广义后缀自动机_单调队列
没啥难的,主要是单调队列忘了咋求了QAQ... Code: #include <cstdio> #include <algorithm> #include <cstrin ...
- SP10628 COT - Count on a tree 主席树
Code: #include<cstdio> #include<cstring> #include<algorithm> #include<string> ...