[BZOJ4816][SDOI2017]数字表格(莫比乌斯反演)
来源:互联网 发布:2017年时代网络诗人奖 编辑:程序博客网 时间:2024/05/24 04:17
容易看出,此题用莫比乌斯反演求解。
首先,要把
所以:
而
即原式等于
继续考虑。可以发现,
这样就可以将
代码:
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;inline int read() { int res = 0; bool bo = 0; char c; while (((c = getchar()) < '0' || c > '9') && c != '-'); if (c == '-') bo = 1; else res = c - 48; while ((c = getchar()) >= '0' && c <= '9') res = (res << 3) + (res << 1) + (c - 48); return bo ? ~res + 1 : res;}const int MaxN = 1e6, PYZ = 1e9 + 7, N = MaxN + 5;int tot, f[N], g[N], pri[N], miu[N], F[N], prod[N];bool mark[N];int qpow(int a, int b) { int res = 1; while (b) { if (b & 1) res = 1ll * res * a % PYZ; a = 1ll * a * a % PYZ; b >>= 1; } return res;}void sieve() { int i, j; f[0] = 0; f[1] = miu[1] = g[1] = F[1] = prod[0] = 1; mark[0] = mark[1] = 1; for (i = 2; i <= MaxN; i++) { f[i] = (f[i - 1] + f[i - 2]) % PYZ; g[i] = qpow(f[i], PYZ - 2); F[i] = 1; if (!mark[i]) pri[++tot] = i, miu[i] = -1; for (j = 1; j <= tot; j++) { if (1ll * i * pri[j] > MaxN) break; mark[i * pri[j]] = 1; if (i % pri[j] == 0) break; else miu[i * pri[j]] = -miu[i]; } } for (i = 1; i <= MaxN; i++) { if (miu[i] != 0) for (j = i; j <= MaxN; j += i) F[j] = 1ll * F[j] * (miu[i] == 1 ? f[j / i] : g[j / i]) % PYZ; prod[i] = 1ll * prod[i - 1] * F[i] % PYZ; }}int solve(int a, int b) { int i, n = min(a, b), ans = 1; for (i = 1; i <= n;) { int nxt = min(a / (a / i), b / (b / i)), pro; pro = 1ll * prod[nxt] * qpow(prod[i - 1], PYZ - 2) % PYZ; ans = 1ll * ans * qpow(pro, 1ll * (a / i) * (b / i) % (PYZ - 1)) % PYZ; i = nxt + 1; } return ans;}int main() { int a, b, T = read(); sieve(); while (T--) a = read(), b = read(), printf("%d\n", solve(a, b)); return 0;}
阅读全文
0 0
- [BZOJ4816][SDOI2017]数字表格(莫比乌斯反演)
- [莫比乌斯反演] BZOJ4816: [Sdoi2017]数字表格
- bzoj 4816: [Sdoi2017]数字表格 莫比乌斯反演
- [莫比乌斯反演] BZOJ 4816 [Sdoi2017]数字表格
- [数论 反演]BZOJ4816 [Sdoi2017]数字表格
- LOj 2000「SDOI2017」数字表格 (莫比乌斯反演)
- BZOJ4816 [Sdoi2017]数字表格
- bzoj4816: [Sdoi2017]数字表格
- 【bzoj4816】[Sdoi2017]数字表格
- [bzoj4816][SDOI2017]数字表格
- bzoj4816: [Sdoi2017]数字表格
- BZOJ4816: [Sdoi2017]数字表格
- [BZOJ4816][Sdoi2017]数字表格 数学
- loj #2000. 「SDOI2017」数字表格 (莫比乌斯)
- 【BZOJ4816】数字表格,反演+枚举约数
- [BZOJ2154]Crash的数字表格 && 莫比乌斯反演
- 【莫比乌斯反演】[BZOJ2154]Crash的数字表格
- 【bzoj2154】【Crash的数字表格】【莫比乌斯反演】
- 使用阿里巴巴提供的约束规范
- TensorFlow 深度学习笔记 TensorFlow实现与优化深度神经网络
- kinect+opencv+mfc读取彩色摄像头
- 详述 IntelliJ IDEA 插件的安装及使用方法
- linux入门5
- [BZOJ4816][SDOI2017]数字表格(莫比乌斯反演)
- unity中的旋转
- 阿里云centos环境之tomcat配置<三>
- 单件模式
- css-垂直居中多种解决方式
- 卷积神经网络——输入层、卷积层、激活函数、池化层、全连接层
- JavaWeb 解决中文传参乱码
- pulltorefresh上拉下拉刷新的用法
- ubuntu64-server安装