题目: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. POJ3246-Balanced Lineup,好经典的题,做法和HDU-I hate it 一样~~

    Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K   Case Time Limit: 2000MS Description For ...

  2. Circling Round Treasures(codeforces 375c)

    题意:要求在一张网格图上走出一条闭合路径,不得将炸弹包围进去,使围出的总价值减去路径长度最大. /* 类似于poj3182的做法,只不过出现了多个点,那么就用状态压缩的方法记录一个集合即可. */ # ...

  3. Codevs 队列练习 合并版

    3185 队列练习 1  时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给定一个队列(初始为空),只有两种操作入队和出队,现给出这 ...

  4. HDU 6390

    GuGuFishtion Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  5. 动态规划:HDU 1114 Piggy-Bank

    Problem Description Before ACM can do anything, a budget must be prepared and the necessary financia ...

  6. Spring Data JPA 进阶

    Java持久化查询语言概述 Java持久化查询语言(JPQL)是一种可移植的查询语言,旨在以面向对象表达式语言的表达式,将SQL语法和简单查询语义绑定在一起,使用这种语言编写的查询是可移植的,可以被编 ...

  7. html5开发手机打电话发短信功能

    原文:http://www.open-open.com/code/view/1449843459332 在很多的手机网站上,有打电话和发短信的功能,对于这些功能是如何实现的呢.其实不难,今天我们就用h ...

  8. 定制 ArcEngine 要素编辑工具

    来自:http://blog.sina.com.cn/s/blog_4d780fc10101d2d5.html 先初步了解到大概用到的下面的接口和类: IEngineEditor IEngineEdi ...

  9. jenkins修改日志级别方法

    1.jenkins日志有时候也会消耗掉很大内存,在传输时也会消耗掉大量带宽,如图,300+M的日志大小,太夸张了吧 2.修改日志级别的方法: 在配置文件里修改,重启后永久生效,配置路径:/etc/sy ...

  10. javascript array-like object

    http://www.nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/ ...