結果
| 問題 | 
                            No.2767 Add to Divide
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-06-01 11:54:55 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 815 bytes | 
| コンパイル時間 | 4,217 ms | 
| コンパイル使用メモリ | 263,392 KB | 
| 実行使用メモリ | 10,496 KB | 
| 最終ジャッジ日時 | 2024-12-21 18:21:30 | 
| 合計ジャッジ時間 | 13,432 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 13 TLE * 3 | 
ソースコード
#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;
    }
    bool found = false;
    int mi = 2e9;
    for (int k = 2; k * a < b; k++) {
      int num = b - k * a;
      int den = k - 1;
      int x = num / den;
      if (num % den == 0) {
        if ((b + x) % ((a + x) * k) == 0) {
          mi = min(mi, x);
          found = true;
        }
      }
    }
    if (found) {
      cout << mi << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;  
}