結果

問題 No.2767 Add to Divide
ユーザー Nzt3Nzt3
提出日時 2024-06-01 13:05:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 584 bytes
コンパイル時間 2,266 ms
コンパイル使用メモリ 199,744 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-01 13:05:34
合計ジャッジ時間 2,987 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int MOD=998244353;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
void solve();
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int test_case;
  cin>>test_case;
  while (test_case--){
    solve();
  }
}
void solve(){
  int A,B;
  cin>>A>>B;
  if(B%A==0){
    cout<<"0\n";
    return;
  }
  int C=B-A;
  int X=C+7;
  for(int i=1;i*i<=C;i++){
    if(C%i==0){
      if(i>=A)X=min(X,i-A);
      if(C/i>=A)X=min(X,C/i-A);
    }
  }
  if(X>C)X=-1;
  cout<<X<<'\n';
}
0