CF 757 E Bash Plays with Functions —— 积性函数与质因数分解
题目: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 —— 积性函数与质因数分解的更多相关文章
- CF 757E Bash Plays with Functions——积性函数+dp+质因数分解
题目:http://codeforces.com/contest/757/problem/E f0[n]=2^m,其中m是n的质因子个数(种类数).大概是一种质因数只能放在 d 或 n/d 两者之一. ...
- 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 ...
- Codeforces E. Bash Plays with Functions(积性函数DP)
链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...
- 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 ...
- 【codeforces 757E】Bash Plays with Functions
[题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...
- codeforces757E. Bash Plays with Functions(狄利克雷卷积 积性函数)
http://codeforces.com/contest/757/problem/E 题意 Sol 非常骚的一道题 首先把给的式子化一下,设$u = d$,那么$v = n / d$ $$f_r(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 757E] Bash Plays with Functions (数论)
题目链接: http://codeforces.com/contest/757/problem/E?csrf_token=f6c272cce871728ac1c239c34006ae90 题目: 题解 ...
- CF757E Bash Plays with Functions
题解 q<=1e6,询问非常多.而n,r也很大,必须要预处理所有的答案,询问的时候,能比较快速地查询. 离线也是没有什么意义的,因为必须递推. 先翻译$f_0(n)$ $f_0(n)=\sum_ ...
随机推荐
- hdu 2167 状态压缩
/*与1565的解法差不多*/ #include<stdio.h> #include<string.h> int map[16][16]; int dp[2][1<< ...
- ISAPI映射路径错误,导致K3Cloud打不开。
今天一个同事说她的K3Cloud打不开,一看是页面报500错误,具体信息看图片: 问题: ISAPI配置的映射路径错了,多了个反斜线. 解决办法: 在IIS管理器中找到ISAPI筛选器,删除掉就行了.
- 给你两个字符串str1,str2,找出str2在str1中的位置
如题 题目参考链接: http://blog.csdn.net/hxz_qlh/article/details/14110221 代码来自非原创 #include <iostream> # ...
- msp430入门编程25
msp430中C语言开发环境搭建 msp430入门学习 msp430入门编程
- secure上传图片
1.rz -bye 2.upload as ascii 去掉勾选框
- 洛谷 P4720 【模板】扩展 / 卢卡斯 模板题
扩展卢卡斯定理 : https://www.luogu.org/problemnew/show/P4720 卢卡斯定理:https://www.luogu.org/problemnew/show/P3 ...
- SpringMvc架构流程
- java学习——关于搜索异常处理的总结
根据网上的资料可以知道,异常处理是为了检测到程序运行中发生的非正常情况的检测而设立的一种机制,异常的英文单词是exception,字面翻译就是“意外.例外”的意思,也就是非正常情况.关于平常我们经常遇 ...
- Spring的JDBC框架概述
以下内容引用自http://wiki.jikexueyuan.com/project/spring/jdbc-framework.html: 在使用普通的JDBC操作数据库时,就会很麻烦的写很多不必要 ...
- sql server2008 R2 各个版本的区别与选择
目前已知的SQL Server 2008 R2的版本有: 企业版.标准版.工作组版.Web版.开发者版.Express版.Compact 3.5版. 这个次序也是各个版本功能的强大程度从高到低的一个排 ...