結果
| 問題 | 
                            No.2767 Add to Divide
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-05-31 22:07:05 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 972 bytes | 
| コンパイル時間 | 1,579 ms | 
| コンパイル使用メモリ | 106,916 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-12-20 23:37:30 | 
| 合計ジャッジ時間 | 2,614 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 12 WA * 4 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
constexpr int iINF = 1'000'000'000;
constexpr ll llINF = 1'000'000'000'000'000'000;
vector<int> divisors (int x) {
    vector<int> res;
    for (int i = 1; 1LL * i * i <= x; i++) {
        if (x % i == 0) res.push_back(i);
        if (1LL * i * i == x) continue;
        res.push_back(x / i);
    }
    sort(res.begin(), res.end());
    return res;
}
void solve (int A, int B) {
    if (A == 1) {
        cout << 0 << "\n";
        return;
    }
    auto d = divisors(B - A);
    int ans = -1;
    for (auto v : d) {
        if (A <= v) {
            int candi = v - A;
            if ((B + candi) % (A + candi) == 0) {
                ans = candi;
                break;
            }
        }
    }
    cout << ans << "\n";
}
int main () {
    int T; cin >> T;
    for (int i = 0; i < T; i++) {
        int A, B; cin >> A >> B;
        solve(A, B);
    }
}