Floor and Mod(CF1485C)(数论)

时间:2021-02-17 15:13:35   收藏:0   阅读:0

题意:
问多少对 \(a,b\) 满足 \(\lfloor \frac{a}{b} \rfloor =a\ mod\ b\)
其中 \(1\leqslant a\leqslant x,1\leqslant b\leqslant y\)


想法:


代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
const int maxn=100005;

int main()
{
    int T;
    ll a,b;
    cin>>T;
    while(T--){
        scanf("%lld%lld",&a,&b);
        ll num=sqrt(a+1);
        ll ans=0;
        if(num>b){
            num=b;
            ans+=(num)*(num-1)/2;
        }else{
            ans+=(num)*(num-1)/2;
            for(ll l=num+1,r;l<=min(a,b);l=r+1){
                if(a/(l+1)==0)break;
                else{
                    r=min(b,min(a,a/(a/(l+1))-1));
                }
                ans+=(r-l+1)*(a/(l+1));
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!