結果
| 問題 | 
                            No.2767 Add to Divide
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-06-01 12:46:14 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 13 ms / 2,000 ms | 
| コード長 | 718 bytes | 
| コンパイル時間 | 3,805 ms | 
| コンパイル使用メモリ | 263,264 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-21 19:37:26 | 
| 合計ジャッジ時間 | 4,160 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 16 | 
ソースコード
#pragma GCC optimize "O3,omit-frame-pointer,inline"
#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main () {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    if (b % a == 0) {
     cout << 0 << endl;
     continue;
    }
    int n = b - a;
    int ans = 2e9;
    for (int c = 1; c * c <= n; c++) {
      if (n % c == 0) {
        int x = c;
        int y = n / c;
        if (x - a >= 0) ans = min(ans, x - a);
        if (y - a >= 0) ans = min(ans, y - a);
      }
    }
    cout << (ans == 2e9 ? -1 : ans) << endl;
  }
  return 0;  
}