結果

問題 No.2767 Add to Divide
ユーザー tobbie
提出日時 2024-07-16 22:04:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 541 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 166,736 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-16 22:04:23
合計ジャッジ時間 2,392 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define INF 1000000001

int main() {
  int T;
  cin >> T;
  rep(i, T) {
    int A, B;
    cin >> A >> B;
    int X = INF;
    if (B - A == 0)
      X = 0;
    else
      for (int j = 1; j*j <= B - A; j++) {
	int c = B - A;
	if (c % j == 0) {
	  if (c / j - A >= 0)
	    X = min(c / j - A, X);
	  if (j - A >= 0)
	    X = min(j - A, X);
	}
      }
    if (X == INF)
      cout << -1 << endl;
    else
      cout << X << endl;
  }
  return 0;
}
0