[CF1485C] Floor and Mod

[CF1485C] Floor and Mod - 数论

Description

(1le ale x,1le ble y)(lfloorfrac{a}{b} floor =amod b)((a,b)) 个数

Solution

(lfloorfrac{a}{b} floor =amod b = r),这个 r 显然是不会超过 (sqrt a) 的,一次枚举即可

对于一个确定的 r,方案数是可以 O(1) 求出的

#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    ios::sync_with_stdio(false);

    int t;
    cin >> t;

    while (t--)
    {
        int x, y;
        cin >> x >> y;

        int ans = 0;
        for (int i = 1; i <= 5e4; i++)
            ans += max(0ll, min(y, x / i - 1) - i);

        cout << ans << endl;
    }
}
原文地址:https://www.cnblogs.com/mollnn/p/14439706.html