找寻一个好的向上取整数论分块的板子如同大海捞针
虽然说就是很唐地 $\lceil \dfrac{x}{i} \rceil = \lfloor \dfrac{x + i - 1}{i} \rfloor = \lfloor \dfrac{x - 1}{i} \rfloor + 1 $,但是还是岩鬣谴责!浪费我好多时间!
下面是算 \(x\) 对 \([1, n]\) 的向上取整数论分块。
void add(int x) {
for (int l = 1, r; l <= n; l = r + 1) {
int k = (x + l - 1) / l;
if (k == 1) r = n;
else r = (x - 1) / (k - 1);
// [l, r] -> k
}
}
Posted by liuzimingc