結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

int main() {
    int T;
    cin >> T;

    while (T--) {
        ll A, B;
        cin >> A >> B;

        vector<ll> divisors;
        for (ll i = 1; i * i <= B - A; i++) {
            if ((B - A) % i == 0) {
                divisors.push_back(i);
                if (i * i != B - A) divisors.push_back((B - A) / i);
            }
        }

        sort(divisors.begin(), divisors.end());

        ll ans = INFL;
        for (ll d : divisors) {
            if (d >= A) {
                ans = min(ans, d - A);
            }
        }

        if (ans == INFL) {
            cout << -1 << endl;
        } else {
            cout << ans << endl;
        }
    }
}
0