hdu 4675 GCD of Sequence(计数)
来源:互联网 发布:淘宝试衣间在哪 编辑:程序博客网 时间:2024/05/21 10:19
题目链接:hdu 4675 GCD of Sequence
代码
#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int maxn = 300000;const int mod = 1e9 + 7;int fac[maxn + 5], inv[maxn + 5];vector<int> P[maxn + 5];int pow_mod(int x, int n) { if (n < 0) return 0; int ret = 1; while (n) { if (n&1) ret = 1LL * ret * x % mod; x = 1LL * x * x % mod; n >>= 1; } return ret;}void presolve (int n) { for (int i = 0; i <= n; i++) P[i].clear(); for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j += i) P[j].push_back(i); } fac[0] = inv[0] = 1; for (int i = 1; i <= n; i++) fac[i] = 1LL * fac[i-1] * i % mod; inv[n] = pow_mod(fac[n], mod-2); for (int i = n-1; i; i--) inv[i] = 1LL * inv[i+1] * (i+1) % mod;}int C(int n, int k) { if (n < 0 || k < 0 || k > n) return 0; return 1LL * fac[n] * inv[k] % mod * inv[n-k] % mod;}int N, M, K, cnt[maxn + 5], ans[maxn + 5];void init () { int x; memset(cnt, 0, sizeof(cnt)); for (int i = 1; i <= N; i++) { scanf("%d", &x); for (int j = 0; j < P[x].size(); j++) cnt[P[x][j]]++; }}int main () { presolve(maxn); while (scanf("%d%d%d", &N, &M, &K) == 3) { init(); for (int i = M; i; i--) { int k = M / i; ans[i] = 1LL * C(cnt[i], N-K) * pow_mod(k-1, cnt[i]-N+K) % mod * pow_mod(k, N-cnt[i]) % mod; for (int j = 2; j * i <= M; j++) ans[i] = (ans[i] - ans[j*i]) % mod; ans[i] = (ans[i] + mod) % mod; } for (int i = 1; i <= M; i++) printf("%d%c", ans[i], i == M ? '\n' : ' '); } return 0;}
0 0
- hdu 4675 GCD of Sequence(计数)
- HDU 4675 GCD of Sequence(数学)
- HDU 4675 GCD of Sequence
- HDU 4675 GCD of Sequence
- HDU4675-GCD of Sequence(数论+组合计数)
- 解题报告: HDU_4675 GCD of Sequence 计数
- HDU 4675 GCD of Sequence (莫比乌斯反演)
- HDU 4675GCD of Sequence(大组合数取模 容斥原理 组合数学)
- HDU 4675-GCD of Sequence(莫比乌斯反演+组合数+逆元)
- HDU4675 GCD of Sequence
- hdu 5400 Arithmetic Sequence(计数)
- hdu 4908 BestCoder Sequence(计数)
- HDU - 4497 - GCD and LCM (线性筛素数 + 计数)
- hdu 4497 GCD and LCM (唯一分解定理 + 计数)
- hdu 5381 The sum of gcd(线段树+gcd)
- [BestCoder Round #3] hdu 4908 BestCoder Sequence (计数)
- HDU 4390 Number Sequence (容斥原理+组合计数)
- HDU 6078 Wavel Sequence 计数dp(思维)
- 使用DrawImage函数进行拉伸绘制时出现的过度边沿现象
- 喜马拉雅听 手机端协议分析
- hdu 4672 Present Day, Present Time(博弈)
- 【MySQL】mysql中模糊查询的四种用法
- 使用oschina的git服务器图文流程
- hdu 4675 GCD of Sequence(计数)
- C++常见类型所占字节大小
- linux shell(2)
- 蓝懿ios 技术内容和心得交流分享 11.6
- Introduction to Algorithm - Summary of Chapter 7 - Quicksort
- iOS开发——高德地图调研之显示地图、定位与地理编码等
- MFC对话框屏幕居中
- ZigZag Convertion
- HDU 3724 Encoded Barcodes (2010 Asia Tianjin Regional Contest )