結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 12 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 12 ms
6,944 KB
testcase_06 AC 13 ms
6,940 KB
testcase_07 AC 12 ms
6,940 KB
testcase_08 AC 12 ms
6,944 KB
testcase_09 AC 12 ms
6,940 KB
testcase_10 AC 13 ms
6,944 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

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<=10000;X++)if((B+X)%(A+X)==0)
        {
            ans=X;
            break;
        }
        for(int k=2;B-k*A>=0&&k<=10000;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