結果
| 問題 | 
                            No.2767 Add to Divide
                             | 
                    
| コンテスト | |
| ユーザー | 
                             srjywrdnprkt
                         | 
                    
| 提出日時 | 2024-02-29 17:12:16 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 55 ms / 2,000 ms | 
| コード長 | 593 bytes | 
| コンパイル時間 | 2,011 ms | 
| コンパイル使用メモリ | 192,056 KB | 
| 最終ジャッジ日時 | 2025-02-19 21:59:56 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 16 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int M = 31623;
void solve(){
    ll A, B, mi=2e9;
    cin >> A >> B;
    for (int X=0; X<=M; X++){
        if ((B+X) % (A+X) == 0){
            mi = X;
            break;
        }
    }
    for (int Y=2; Y<=M; Y++){
        if (B-A*Y >= 0 && (B-A*Y) % (Y-1) == 0) mi = min(mi, (B-A*Y) / (Y-1));
    }
    if (mi == 2e9) cout << -1 << '\n';
    else cout << mi << '\n';
}
int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--) solve();
    return 0;
}
            
            
            
        
            
srjywrdnprkt