結果

問題 No.2767 Add to Divide
ユーザー nononnonon
提出日時 2024-05-31 21:46:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 586 bytes
コンパイル時間 2,093 ms
コンパイル使用メモリ 201,372 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-31 21:46:55
合計ジャッジ時間 4,409 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,812 KB
testcase_01 AC 10 ms
6,944 KB
testcase_02 AC 23 ms
6,944 KB
testcase_03 AC 102 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 106 ms
6,944 KB
testcase_06 AC 104 ms
6,940 KB
testcase_07 AC 105 ms
6,940 KB
testcase_08 AC 106 ms
6,944 KB
testcase_09 AC 104 ms
6,940 KB
testcase_10 AC 105 ms
6,940 KB
testcase_11 AC 119 ms
6,940 KB
testcase_12 AC 102 ms
6,944 KB
testcase_13 AC 115 ms
6,940 KB
testcase_14 AC 114 ms
6,940 KB
testcase_15 AC 139 ms
6,940 KB
testcase_16 AC 138 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin>>T;
    while(T--)
    {
        long A,B;
        cin>>A>>B;
        int ans=1<<30;
        for(int X=0;X<=100000;X++)if((B+X)%(A+X)==0)
        {
            ans=X;
            break;
        }
        for(int k=2;B-k*A>=0&&k<=100000;k++)
        {
            if((B-k*A)%(k-1)==0)
            {
                int X=(B-k*A)/(k-1);
                ans=min(ans,X);
            }
        }
        if(ans==1<<30)ans=-1;
        cout<<ans<<'\n';
    }
}
0