【题目链接】:http://codeforces.com/problemset/problem/757/E

【题意】



给你q个询问;

每个询问包含r和n;

让你输出f[r][n];

这里f[0][n]是n分解成两个数u,v的乘积的个数;

这里u和v互质;

而f[r][n]当r>0时,有个递推式;

【题解】



那个递推式等价于



即n的所有因子x的f[r][x]的和;

这里需要知道;

f[0][n]=2n的不同质因子个数

且容易得到

当a和b互质的时候,f[0][a*b]=f[0][a]*f[0][b];

则f[0]是积性函数;

有个定理就是;

如果是类似上面那个递推

如果且f为积性函数,则g也为积性函数;

则我们在算

f[r][n]的时候可以对n分解质因数;

即f[r][p1^q1*p2^q2…pm^qm];

这样p1^q1..p2^q2..pm^qm都是互质的了;

则可以利用积性函数把它们分解成

f[r][p1^q1]*f[r][p2^q2]..*f[r][pm^qm];

这里

f[0][p^q]的值除了q=0的时候为1之外,其他情况都为2,因为p是质数,可知不同的质因子个数只有1个,也即这个质数p;所以都是2^1;

q为0的时候,只有1,1这种情况,所以只有一对;为1;

(所以这里的p只要为质数,是几都无所谓,f[0]的值都一样)



根据

可知

f[r+1][pq]=∑f[r][p0..q]⋅⋅⋅①

因为p0..q都是pq的因子

这样其实就能看出来了,要算f[r][p^q]的时候,根本不需要知道p是多少;

f[r][p^q]只与q和r有关;

根据①式能够很容易写个dp;

具体的

g[0][0] = 1,g[0][1..n] = 2;

g[i][0] = g[i-1][0];

g[i][j]=∑g[i−1][0..j]

对于要算的

f[r][p1q1]∗f[r][p2q2]..∗f[r][pmqm];

直接输出

g[r][q1]∗g[r][q2]∗...∗g[r][qm]

就好;

在对n分解质因数的时候,好像用到了更牛逼的方式.

类似筛法的东西吧.

快速获取某个值的质因子;

(用cin竟然会超时…再也不用了!…还是算了吧,cin还是比较方便的,记住可能会因为这个超时就好…)



【Number Of WA】



5



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e6;
const int MOD = 1e9+7; int dp[N+100][21],lp[N+10]; void pre()
{
lp[1] = 1;
rep1(i,2,N)
if (lp[i]==0)
for (int j = i;j<=N;j+=i)
lp[j] = i; rep1(i,1,20)
dp[0][i] = 2;
rep1(i,0,N)
dp[i][0] = 1;
rep1(i,1,N)
rep1(j,1,20)
dp[i][j] = (dp[i][j-1] + dp[i-1][j])%MOD;
} int main()
{
//Open();
pre();
int q;
scanf("%d",&q);
while (q--)
{
int r,n;
scanf("%d%d",&r,&n);
LL ans = 1;
while (n>1)
{
int cnt = 0,x = lp[n];
while (n%x==0)
{
cnt++;
n/=x;
}
ans = (ans*dp[r][cnt])%MOD;
}
printf("%lld\n",ans);
}
return 0;
}

【codeforces 757E】Bash Plays with Functions的更多相关文章

  1. 【codeforces 757B】 Bash's Big Day

    time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  2. 【Codeforces 757B】 Bash's big day

    [题目链接] 点击打开链接 [算法] 若gcd(s1,s2,s3....sk) > 1, 则说明 : 一定存在一个整数d满足d|s1,d|s2,d|s3....,d|sk 因为我们要使|s|尽可 ...

  3. 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 ...

  4. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  5. 【codeforces 789C】Functions again

    [题目链接]:http://codeforces.com/contest/789/problem/C [题意] 看式子. [题解] 考虑最后的答案区间; 如果那个区间是从奇数位置的数字开始的; 那么奇 ...

  6. 【30.49%】【codeforces 569A】Music

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【codeforces 757A】Gotta Catch Em' All!

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【codeforces 754B】 Ilya and tic-tac-toe game

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【codeforces 604D】Moodular Arithmetic

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. js面向对象编程: js类定义函数时prototype和this差别?

    在面向对象编写js脚本时,定义实例方法主要有两种 例如以下: function ListCommon2(afirst) { var first=afirst; this.do1=function () ...

  2. Swift开发教程--怎样自己定义TabBarItem的图片显示

    在做项目的时候,假设使用系统的UITabBarController的时候,底部的tab自己定义图片显示是蓝色和灰色的.这不是我们所想要的效果. 假设想显示自己定义的按下和弹起的图片效果.这个时候就须要 ...

  3. Auto property synthesis will not synthesize property &#39;delegate&#39;; it will be implemented by its super

    今天在XCode6.3上面重写TabBar的时候,自己定义tabBar的代理遇到的一个问题 在重写tabBar的代理的时候遇到了一个警告. 解决方法: 在.m文件里 警告消失

  4. bzoj1924: [Sdoi2010]所驼门王的宝藏

    陈年老题又来水一发啊啊啊 构图狗了一点,然后其实强连通缩点dij找最长路就没了. 没调出来有点气,直接打了第9个点的表.... 来逛blog的你教教我呗 #include<cstdio> ...

  5. Python 加载数据

    1. numpy data = np.loadtxt('./data/txtdata.csv') ⇒ data 是 numpy.ndarray 类型

  6. NESTED LOOPS & HASH JOIN & SORT MERGE JOIN

    表连接方式及使用场合 NESTED LOOP 对于被连接的数据子集较小的情况,nested loop连接是个较好的选择.nested loop就是扫描一个表,每读到一条记录,就根据索引去另一个表里面查 ...

  7. 【POJ 2828】Buy Tickets

    [题目链接] http://poj.org/problem?id=2828 [算法] 离线用线段树维护序列即可 [代码] #include <algorithm> #include < ...

  8. 39.Qt XML

    1.使用QXmlStreamReader读取XML,可以读取内存中容纳不了的特大文件,或者读取在XML文档中定制的文档的内容. xml文件(in1.xml) <?xml version=&quo ...

  9. tomcat开启https服务

    一.创建证书 证书是单点登录认证系统中很重要的一把钥匙,客户端于服务器的交互安全靠的就是证书:本教程由于是演示所以就自己用JDK自带的keytool工具生成证书:如果以后真正在产品环境中使用肯定要去证 ...

  10. Load和CPU利用率是如何算出来的

    相信很多人都对Linux中top命令里“load average”这一栏困惑过,到底什么是Load,Load代表了什么含义,Load高会有什么后果?“%CPU”这一栏为什么会超过100%,它是如何计算 ...