結果

問題 No.2767 Add to Divide
ユーザー GOTKAKO
提出日時 2024-05-31 21:33:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 601 bytes
コンパイル時間 2,003 ms
コンパイル使用メモリ 197,980 KB
最終ジャッジ日時 2025-02-21 17:33:27
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T; cin >> T;
    while(T--){
        long long a,b; cin >> a >> b;
        if(a == b){cout << 0 << endl; continue;}
        long long diff = b-a;

        vector<long long> D;
        for(int i=1; i*i<=diff; i++){
            if(diff%i) continue;
            D.push_back(i);
            D.push_back(diff/i);
        }
        sort(D.begin(),D.end());
        int answer = -1;
        for(auto d : D) if(d >= a){answer = d-a; break;}
        cout << answer << endl;
    }
}
0