結果

問題 No.2767 Add to Divide
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-02-29 17:12:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 593 bytes
コンパイル時間 2,180 ms
コンパイル使用メモリ 200,040 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-08 14:06:16
合計ジャッジ時間 3,433 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 5 ms
5,376 KB
testcase_02 AC 10 ms
5,376 KB
testcase_03 AC 37 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 37 ms
5,376 KB
testcase_06 AC 37 ms
5,376 KB
testcase_07 AC 37 ms
5,376 KB
testcase_08 AC 37 ms
5,376 KB
testcase_09 AC 37 ms
5,376 KB
testcase_10 AC 38 ms
5,376 KB
testcase_11 AC 52 ms
5,376 KB
testcase_12 AC 49 ms
5,376 KB
testcase_13 AC 50 ms
5,376 KB
testcase_14 AC 52 ms
5,376 KB
testcase_15 AC 43 ms
5,376 KB
testcase_16 AC 43 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int M = 31623;

void solve(){
    ll A, B, mi=2e9;
    cin >> A >> B;

    for (int X=0; X<=M; X++){
        if ((B+X) % (A+X) == 0){
            mi = X;
            break;
        }
    }

    for (int Y=2; Y<=M; Y++){
        if (B-A*Y >= 0 && (B-A*Y) % (Y-1) == 0) mi = min(mi, (B-A*Y) / (Y-1));
    }

    if (mi == 2e9) cout << -1 << '\n';
    else cout << mi << '\n';
}

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

    int T;
    cin >> T;

    while(T--) solve();

    return 0;
}
0