F - Cowslip Collections

http://codeforces.com/blog/entry/43868 这个题解讲的很好。。。

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define fi first
  4. #define se second
  5. #define mk make_pair
  6. #define PII pair<int, int>
  7. #define PLI pair<LL, int>
  8. #define ull unsigned long long
  9. using namespace std;
  10.  
  11. const int N = 1e6 + ;
  12. const int inf = 0x3f3f3f3f;
  13. const LL INF = 0x3f3f3f3f3f3f3f3f;
  14. const int mod = 1e9 + ;
  15. const double eps = 1e-;
  16.  
  17. LL inv[N], f[N], finv[N], phi[N];
  18. int n, k, q, a[N], in[N], cnt[N];
  19. vector<int> fac[N];
  20.  
  21. void init() {
  22. inv[] = f[] = finv[] = ;
  23. for(int i = ; i < N; i++) inv[i] = (mod-mod/i)*inv[mod%i]%mod;
  24. for(int i = ; i < N; i++) f[i] = f[i-]*i%mod;
  25. for(int i = ; i < N; i++) finv[i] = finv[i-]*inv[i]%mod;
  26. iota(phi, phi + N, );
  27. for(int i = ; i < N; i++) {
  28. for(int j = i; j < N; j += i) {
  29. if(i != j) phi[j] -= phi[i];
  30. if(in[j]) fac[j].push_back(i);
  31. }
  32. }
  33. }
  34. LL comb(int n, int m) {
  35. if(n < m || n < ) return ;
  36. return f[n]*finv[n-m]%mod*finv[m]%mod;
  37. }
  38. int main() {
  39. scanf("%d%d%d", &n, &k, &q);
  40. for(int i = ; i <= n + q; i++) scanf("%d", &a[i]), in[a[i]] = ;
  41. init();
  42. LL ans = ;
  43. for(int i = ; i <= n + q; i++) {
  44. for(int t : fac[a[i]]) {
  45. ans = (ans + phi[t]*((comb(cnt[t]+, k)-comb(cnt[t], k)+mod)%mod)%mod)%mod;
  46. cnt[t]++;
  47. }
  48. if(i > n) printf("%lld\n", ans);
  49. }
  50. return ;
  51. }
  52.  
  53. /*
  54. */

CROC 2016 - Elimination Round (Rated Unofficial Edition) F - Cowslip Collections 数论 + 容斥的更多相关文章

  1. CROC 2016 - Elimination Round (Rated Unofficial Edition) D. Robot Rapping Results Report 二分+拓扑排序

    D. Robot Rapping Results Report 题目连接: http://www.codeforces.com/contest/655/problem/D Description Wh ...

  2. CROC 2016 - Elimination Round (Rated Unofficial Edition) D. Robot Rapping Results Report 拓扑排序+二分

    题目链接: http://www.codeforces.com/contest/655/problem/D 题意: 题目是要求前k个场次就能确定唯一的拓扑序,求满足条件的最小k. 题解: 二分k的取值 ...

  3. CROC 2016 - Elimination Round (Rated Unofficial Edition) E - Intellectual Inquiry dp

    E - Intellectual Inquiry 思路:我自己YY了一个算本质不同子序列的方法, 发现和网上都不一样. 我们从每个点出发向其后面第一个a, b, c, d ...连一条边,那么总的不同 ...

  4. CROC 2016 - Elimination Round (Rated Unofficial Edition) E. Intellectual Inquiry 贪心 构造 dp

    E. Intellectual Inquiry 题目连接: http://www.codeforces.com/contest/655/problem/E Description After gett ...

  5. CROC 2016 - Elimination Round (Rated Unofficial Edition) C. Enduring Exodus 二分

    C. Enduring Exodus 题目连接: http://www.codeforces.com/contest/655/problem/C Description In an attempt t ...

  6. CROC 2016 - Elimination Round (Rated Unofficial Edition) B. Mischievous Mess Makers 贪心

    B. Mischievous Mess Makers 题目连接: http://www.codeforces.com/contest/655/problem/B Description It is a ...

  7. CROC 2016 - Elimination Round (Rated Unofficial Edition) A. Amity Assessment 水题

    A. Amity Assessment 题目连接: http://www.codeforces.com/contest/655/problem/A Description Bessie the cow ...

  8. CF #CROC 2016 - Elimination Round D. Robot Rapping Results Report 二分+拓扑排序

    题目链接:http://codeforces.com/contest/655/problem/D 大意是给若干对偏序,问最少需要前多少对关系,可以确定所有的大小关系. 解法是二分答案,利用拓扑排序看是 ...

  9. 广东工业大学2016校赛决赛-网络赛 1174 Problem F 我是好人4 容斥

    Problem F: 我是好人4 Description 众所周知,我是好人!所以不会出太难的题,题意很简单 给你n个数,问你1000000000(含1e9)以内有多少个正整数不是这n个数任意一个的倍 ...

随机推荐

  1. centos7.2云主机安装桌面

    yum groups install "X Window System" yum groupinstall "GNOME Desktop" systemctl  ...

  2. 【c#】腾讯人脸识别api签名

    using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using Syst ...

  3. react:在一个组件中调用别的组件中的方法

    先介绍一下要解决的问题:react中一个组件A和一个组件B,其中B是被connect(connect是redux中的方法)包装过的组件,包装成BContainer,A和BContainer的关系是兄弟 ...

  4. Python练习-不知道弄个什么鬼

    Alex大神,今天丢过来一个PDF,结果就成了这个样子! 1.  执行 Python 脚本的两种方式 交互方式:                   命令行 文件方式:                 ...

  5. 关于root

    1.root优缺 android的root跟苹果越狱很类似,可以享受"解禁"后的很多自由. 1.删除系统中不需要的一些app,特别是一些厂商强制安装的app. 2.美化系统,例如修 ...

  6. [转]Laplace算子和Laplacian矩阵

    1 Laplace算子的物理意义 Laplace算子的定义为梯度的散度. 在Cartesian坐标系下也可表示为: 或者,它是Hessian矩阵的迹: 以热传导方程为例,因为热流与温度的梯度成正比,那 ...

  7. tomcat发布html静态页面

    一.环境 在Linux系统安装JDK并配置环境变量,安装tomcat(在tomcat官网下载压缩包即可,我使用的是tomcat7 https://tomcat.apache.org/download- ...

  8. js对金额浮点数运算精度的处理方案

    浮点数产生的原因 浮点数转二进制,会出现无限循环数,计算机又对无限循环小数进行舍入处理 js弱语言的解决方案 方法一: 指定要保留的小数位数(0.1+0.2).toFixed(1) = 0.3;这个方 ...

  9. vue项目中遇到的一些问题

    或访问:https://github.com/littleHiuman/experiences-about-vue  欢迎补充! vuex 状态 vue-cli 命令行 vue vue vue-rou ...

  10. python面向对象(七)属性方法的添加

    ​ 通常情况下,当我们定义了一个class,创建了一个class的实例后,我们可以给该实例绑定任何属性和方法,这就是动态语言的灵活性.下来我就讲下添加属性和方法,同时也将下限值添加属性方法. 添加属性 ...