CF1485C Floor and Mod
fanfansann · · 题解
整套题目全部题解链接:Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13
C - Floor and Mod
Problem C Floor and Mod
Translation
定义一对数
给定
Solution
签到题
看数据范围,显然这是一个结论题或者
因为
所以一个很直观的想法就是枚举
但是需要注意题目中的给定的条件为
即:
即:
即
并且
我们可以先枚举
剩余的
时间复杂度
Code
// Problem: C. Floor and Mod
// Contest: Codeforces - Codeforces Round #701 (Div. 2)
// URL: https://codeforces.com/problemset/problem/1485/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 7;
int n, m, t;
int x, y;
int main()
{
scanf("%d", &t);
while(t -- ) {
scanf("%d%d", &x, &y);
int a = 1, b = 1;
ll ans = 0;
for(; b * b + b - 1 < x && b <= y; ++ b)
ans += (b * b + b - 1) / (b + 1);
int l = b + 1, r;
for(; l <= x && l <= y + 1; l = r + 1) {
r = min(x / (x / l), y + 1);
ans += x / l * (r - l + 1);
if(r == y + 1) break;
}
cout << ans << endl;
}
return 0;
}