結果

問題 No.2882 Comeback
ユーザー karinohitokarinohito
提出日時 2024-09-08 13:54:34
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 2,373 ms
コンパイル使用メモリ 209,452 KB
実行使用メモリ 8,884 KB
最終ジャッジ日時 2024-09-08 13:54:43
合計ジャッジ時間 5,612 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

void solve(){
    ll A,B;
    cin>>A>>B;
    set<ll> S;
    S.insert(A+1);
    S.insert(B+1);
    ll d=1;
    while(d<=B){
        ll L=B/d;
        ll R=B/(d+1);
        S.insert(R+1);
        if(R==0)break;
        d=B/R;
    }
    d=1;
    while(d<=A){
        ll L=A/d;
        ll R=A/(d+1);
        S.insert(R+1);
        if(R==0)break;
        d=A/R;
    }
    vector<ll> D;
    for(int s:S)D.push_back(s);
    ll dn=D.size();
    ll an=0;
    for(int i=0;i<dn-1;i++){
        ll f=B/D[i]-A/D[i];
        ll res=0;
        if(f==0){
            // res=D[i+1]-D[i];
        }
        else res=max(D[i+1]-max(D[i],(B-A+f-1)/f),0ll);
        an+=res;
    }
    cout<<an<<endl;;
}

int main(){
   ll T;
   cin>>T;
   while(T--)solve();
}
0