【题目链接】: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



【完整代码】

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,m,rt<<1
  4. #define rson m+1,r,rt<<1|1
  5. #define LL long long
  6. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  7. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  8. #define mp make_pair
  9. #define pb push_back
  10. #define fi first
  11. #define se second
  12. #define ms(x,y) memset(x,y,sizeof x)
  13. #define Open() freopen("F:\\rush.txt","r",stdin)
  14. #define Close() ios::sync_with_stdio(0),cin.tie(0)
  15. typedef pair<int,int> pii;
  16. typedef pair<LL,LL> pll;
  17. const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
  18. const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
  19. const double pi = acos(-1.0);
  20. const int N = 1e6;
  21. const int MOD = 1e9+7;
  22. int dp[N+100][21],lp[N+10];
  23. void pre()
  24. {
  25. lp[1] = 1;
  26. rep1(i,2,N)
  27. if (lp[i]==0)
  28. for (int j = i;j<=N;j+=i)
  29. lp[j] = i;
  30. rep1(i,1,20)
  31. dp[0][i] = 2;
  32. rep1(i,0,N)
  33. dp[i][0] = 1;
  34. rep1(i,1,N)
  35. rep1(j,1,20)
  36. dp[i][j] = (dp[i][j-1] + dp[i-1][j])%MOD;
  37. }
  38. int main()
  39. {
  40. //Open();
  41. pre();
  42. int q;
  43. scanf("%d",&q);
  44. while (q--)
  45. {
  46. int r,n;
  47. scanf("%d%d",&r,&n);
  48. LL ans = 1;
  49. while (n>1)
  50. {
  51. int cnt = 0,x = lp[n];
  52. while (n%x==0)
  53. {
  54. cnt++;
  55. n/=x;
  56. }
  57. ans = (ans*dp[r][cnt])%MOD;
  58. }
  59. printf("%lld\n",ans);
  60. }
  61. return 0;
  62. }

【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中的call()(转)

    1.方法定义 call方法: 语法:call([thisObj[,arg1[, arg2[, [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象. 说明: call 方 ...

  2. Zookeeper源代码编译为Eclipseproject(win7下Ant编译)

    为了深入学习ZooKeeper源代码,首先就想到将其导入到Eclispe中,所以要先将其编译为Eclispeproject. 1.什么是Ant??? Apache Ant™ Apache Ant is ...

  3. 两列等高布局 padding+margin的负值 CSS布局奇淫技巧之-多列等高

    代码: 效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/ ...

  4. lua 中string字符串的使用(string.len, string.char)

    table.keys 返回指定表格中的全部键. 格式: keys = table.keys(表格对象) 使用方法演示样例: local t = {a = 1, b = 2, c = 3} local ...

  5. swift菜鸟入门视频教程-09-类和结构体

    本人自己录制的swift菜鸟入门,欢迎大家拍砖,有什么问题能够在这里留言. 主要内容: 类和结构体对照 结构体和枚举是值类型 类是引用类型 类和结构体的选择 集合(collection)类型的赋值与复 ...

  6. 2016.03.27,英语,《Vocabulary Builder》Unit 06

    equ: from Latin aequus, meaning 'equal', equalize:使相等; equivalent:[ɪ'kwɪvələnt], A is equivalent to ...

  7. 2014.04.16,读书,读书笔记-《Matlab R2014a完全自学一本通》-第17章 图形用户界面

    界面对象分三类: 用户控件对象(uicontrol) 下拉式菜单对象(uimenu) 内容式菜单对象(uicontextmenu) 创建用户界面: 1.命令行方式 采用uicontrol来创建控件对象 ...

  8. System.setProperty 与 System.getProperty

    转自:https://www.cnblogs.com/woftlcj/p/8404451.html System可以有对标准输入,标准输出,错误输出流:对外部定义的属性和环境变量的访问:加载文件和库的 ...

  9. javascript中的闭包以及闭包应用

    闭包简单理解就是能够读取其他函数内部变量的函数,而在javascript中只有内部函数可以读取函数的内部变量,所以我们学习javascript时可以这样理解,函数A中嵌套了一个函数B,然后我们用函数B ...

  10. java类List及List遍历器的代码

    从某个程序中截取的一个示例代码: List<User> users = userDao.selectAll(); //mybatis java orm Iterator<User&g ...