首页 > 其他 > 详细

[CodeForces1485C]Floor And Mod

时间:2021-02-24 10:19:50      阅读:24      评论:0      收藏:0      [点我收藏+]

discription:
How many pairs \(<a,b>\), s.t. \(a\mod b=\lfloor\frac{a}{b}\rfloor\), for \(1\leqslant a\leqslant x\), $1\leqslant b\leqslant y $ ?
solution:
\(a\mod b= \lfloor \frac{a}{b}\rfloor\)
\(a-\lfloor\frac{a}{b}\rfloor b = \lfloor\frac{a}{b}\rfloor\)
\(a=(b+1)\lfloor\frac{a}{b}\rfloor\), and \(0\leqslant\lfloor\frac{a}{b}\rfloor<b\)

And don‘t forget:
\(1\leqslant a\leqslant x, 1\leqslant b\leqslant y\)

\(\Rightarrow\)How many pairs a,b in the range above, \(s.t.\ a=q(b+1), q\leqslant b-1\)

if \(\forall b\in[1,y],i.e. \frac{x}{b+1}\geqslant b-1\), only \((b-1)\) numbers of divisor of \(x\) ;
else \(i.e.\frac{x}{b+1}< b-1\), two parts of ans, firstly the same as \(\uparrow\), then,without the \(\le(b-1)\) restriction.

\[Answer=\begin{cases} \Sigma_{b=1}^{y}(b-1)=\frac{y(y-1)}2\ ,\ \frac{x}{y+1}\geqslant y-1 \\\\Sigma_{b=1}^{\lfloor\sqrt(x+1)\rfloor}(b-1) + \Sigma_{b=\lfloor\sqrt{x+1}\rfloor+1 } ^ {y}\lfloor\frac{x}{b+1}\rfloor\ ,\ \frac{x}{y+1}<y-1 \end{cases} \]

A.P. and Number Theory div_blocks, we AC this problem.

code:

#include<cstdio>
#include<cmath>
typedef long long ll;
int main() {
	int T; scanf("%d", &T);
	while(T--) {
		int x, y; scanf("%d%d", &x, &y);
		int p = (int)sqrt(x + 1);
		if (y <= p) {
			printf("%d\n", y * (y - 1) >> 1);
			continue;
		}
		ll ans = p*(p-1) >> 1;
		++y;// b+1 --> y+1
		for (int l = p + 2; l <= y;) {
			int t = x / l;
			if (!t) break;// avoid RE.
			int r = x / t;
			if (y < r) r = y;// minimum right bound
			ans += (r - l + 1) * t;
			l = r + 1;
		}
		printf("%lld\n", ans);
	}
}

[CodeForces1485C]Floor And Mod

原文:https://www.cnblogs.com/dwt2021/p/14439033.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!