F题另解

观察数据可得 附近的 尽可能大。根据时间限制尽可能多的枚举。

#include<bits/stdc++.h>
#define int long long 
#define PII pair<int,int>
#define A3 array<int,3>
#define lowbit(x) (x&(-x))
using namespace std;
const int N = 2e5 + 10,inf = 1e18,mod = 998244353;
int T,n,m,k;
signed main(){
    cin.tie(0)->ios::sync_with_stdio(0);
    //cout<<fixed<<setprecision(12);
    cin>>T;
    while(T--){
        int l,r,k; cin>>r>>k;
        int len=r;
        int ans=1ll*(1ll+r)*len/2ll;
        int mx=r/k;
        for(int x=mx-10000ll;x<=mx+10000ll;x++){//枚举gcd
            if(x<=0||x>r) continue;
             int mo=r/x*x,p=r/x;
            if(p<k) continue;
            int res=(x+mo)*p/2ll*x;//等差数列求和*gcd
            ans=max(ans,res);
        }
        cout<<ans<<"\n";
    }
    return 0;
}
/*
g++ -std=c++14 -O2 F.cpp -o work
*/