【BZOJ1257】[CQOI2007]余数之和sum【余数求和】【分块】

详见

http://blog.csdn.net/braketbn/article/details/50715971


#include <cstdio>

typedef unsigned long long ULL;

ULL n, k;

int main() {
	scanf("%llu%llu", &n, &k);
	ULL ans = 0;
	for(ULL i = 1, l, r; i <= n; i = r + 1) {
		ULL d = k / i;
		l = k / (d + 1) + 1;
		r = d ? k / d : n;
		r = r > n ? n : r;
		ans += (k - d * l + k - d * r) * (r - l + 1) / 2;
	}
	printf("%llu\n", ans);
}


你可能感兴趣的:(分块)