\(\text{Solution}\)

发现题目就是求 \(\sum[\prod_{i=1}^k x_i \le n]\)

\(k \le 10^9\) 太可怕了

然而发现如果限定 \(x_i > 1\) 那么 \(i \le \log n\)

于是我们可以愉快地统计了

设 \(f_i(n)\) 表示将 \(n\) 分成 \(i\) 份使 \(x_i > 1\) 的方案数

那么 \(f_i(n)=\sum_{d|n}f_{i-1}(\frac n d)-f_{i-1}(n)\)

那个减号就是减去 \(d=1\) 时的情况

先不考虑减法,发现它的转移就是 \(Dirichlet\) 前缀和

于是处理 \(f\) 可做到 \(O(n \log n \log\log n)\)

每个询问还要枚举多少个位置不填 \(1\),组合算一下方案

总的就是 \(O(n \log n \log\log n + Q \log n)\)

\(\text{Code}\)

#include <cstdio>
#include <iostream>
#define re register
#define LL long long
using namespace std; const int N = 5e5 + 5, P = 998244353;
int mxR, mxK, q, log[N], tot, pr[N], vis[N];
LL f[20][N], inv[20]; inline void read(int &x)
{
x = 0; int f = 1; char ch = getchar();
while (!isdigit(ch)) f = (ch == '-' ? -1 : f), ch = getchar();
while (isdigit(ch)) x = (x<<3) + (x<<1) + (ch^48), ch = getchar();
x *= f;
}
void sieve(int n)
{
for(re int i = 2; i <= n; i++)
{
if (!vis[i]) pr[++tot] = i;
for(re int j = 1; j <= tot && pr[j] * i <= n; j++)
{
vis[pr[j] * i] = 1;
if (i % pr[j] == 0) break;
}
}
}
LL Add(LL x, LL y)
{
x += y;
if (x > P) x -= P;
return x;
} int main()
{
freopen("easy.in", "r", stdin), freopen("easy.out", "w", stdout);
read(mxR), read(mxK), read(q);
sieve(mxR);
for(re int i = 2; i <= mxR; i++) log[i] = log[i >> 1] + 1, f[1][i] = 1;
int lg = log[mxR];
for(re int i = 2; i <= lg; i++)
{
for(re int j = 1; j <= mxR; j++) f[i][j] = f[i - 1][j];
for(re int j = 1; j <= tot; j++)
for(re int k = 1; k * pr[j] <= mxR; k++)
f[i][k * pr[j]] = Add(f[i][k * pr[j]], f[i][k]);
for(re int j = 1; j <= mxR; j++) f[i][j] = Add(f[i][j], P - f[i - 1][j]);
}
for(re int i = 1; i <= lg; i++)
for(re int j = 1; j <= mxR; j++) f[i][j] = Add(f[i][j], f[i][j - 1]);
inv[1] = 1;
for(re int i = 2; i <= lg; i++) inv[i] = (P - P / i) * inv[P % i] % P;
for(int l, r, k; q; q--)
{
read(l), read(r), read(k);
LL ans = 0, c = 1;
for(re int i = 1; i <= log[r]; i++)
{
c = c * (k - i + 1) % P * inv[i] % P;
ans = Add(ans, (f[i][r] - f[i][l - 1] + P) * c % P);
}
printf("%lld\n", ans + (l <= 1));
}
}

最新文章

  1. C#注册表的读,写,删除,查找
  2. 一个简单的左侧固定右侧自适应demo
  3. poj-------(2240)Arbitrage(最短路)
  4. 反人类的MyEclipse之-MyEclipse代码自动补全
  5. CodeForces 589I Lottery (暴力,水题)
  6. MySQL内存表的特性与使用介绍
  7. Android 开发中eclipse 下 DDMS 视图中 sdcard 中文件导入的处理
  8. Claris and XOR(模拟)
  9. Java I/O 总结
  10. mysql免安装版初次使用
  11. 分布式文件系统 fastdfs搭建
  12. sublime text3中文文件名显示为框框,怎么解决
  13. 2.32 js几种定位方法总结
  14. 一个关于react-native的demo,详细请转GitHub
  15. 【OT1.0 + TP3.2】开启trace调试、输出调试信息、开启自定义菜单
  16. Android-一只手指滑动View,另一只手指按Home键,重新进入后View状态无法更新的问题
  17. 看不懂深度Linux系统的文件管理器图标
  18. Spring AOP体系学习总结
  19. 微信小程序开发教程(六)配置——app.json、page.json详解
  20. Mirror--镜像断开的解决办法

热门文章

  1. CSS伪类使用详解
  2. 数电第11周周结_by_yc
  3. Spring Boot回顾
  4. 个人电脑公网IPv6配置
  5. MongoDB - 数据模型的设计模式
  6. pyqt5制作俄罗斯方块小游戏-----源码解析
  7. js将时间戳转成时间格式
  8. Rust-01 启航
  9. S2-052 CVE-2017-9805 远程代码执行
  10. [LeetCode]螺旋矩阵