题目: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. django学习之- Ajax

    提示:jquery要使用1版本,因为高版本已不兼容低版本的游览器.参考url:http://www.cnblogs.com/wupeiqi/articles/5703697.html原生ajax:Aj ...

  2. Construct Binary Tree from Preorder and Inorder Traversal (DFS,参考)

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  3. strstr-strcat实现

    strstr 调用格式 #include <string.h> char *strstr(const char *haystack, const char *needle); 功能说明 该 ...

  4. 初始VueJS视频

    本视频简单的介绍的使用. 初始VueJS视频

  5. [转] ubuntu 下mongodb的安装-----这篇文章也不错

    在Ubuntu下进行MongoDB安装步骤 一. 在Ubuntu下最傻瓜的步骤(以下都在root用户下进行操作): 1.运行"apt-get install mongo" 如果遇到 ...

  6. SharePoint 2013 调查问卷的使用方法

    SharePoint 2013 调查问卷的使用方法 1,介绍调查问卷的用法. 2.图形和全部结果. 3,控制用户仅仅能看到自己答案. 1.确认有权限,假设没有管理管理权限请向管理员申请. 站点&quo ...

  7. android &lt;application&gt; 开发文档翻译

    由于本人英文能力实在有限,不足之初敬请谅解 本博客仅仅要没有注明"转",那么均为原创.转贴请注明本博客链接链接 <application>语法:    <appl ...

  8. ios开发--NSDate与NSDateFormatter的相关用法【转】

    原文地址:http://blog.sina.com.cn/s/blog_91ff71c0010188u9.html 1.NSDateFormatter配合NSDate与NSString之间的转化  N ...

  9. [IT学习]学习Python过程需要记忆的一些坑

    1.列表的引用和复制 A byte of Python 中文4.05c版本85页 单纯对列表进行引用,则列表指向同一对象. 如果你需要复制一份全新的拷贝,则需要通过切片操作. 2.仅有一个元素的元组, ...

  10. 对ASP.NET MVC 的路由一点理解

    这个东西,真搞不懂.看了网上的教程和文章,也不懂(也不清楚写那些文章的人自己是否真的懂).只好靠自己一顿乱摸索. 好比说,下面这个路由: //路由1 config.Routes.MapHttpRout ...