結果
| 問題 | 
                            No.2767 Add to Divide
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-06-01 12:15:58 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 746 bytes | 
| コンパイル時間 | 2,106 ms | 
| コンパイル使用メモリ | 112,224 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-21 18:51:15 | 
| 合計ジャッジ時間 | 2,499 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 12 WA * 4 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
inline std::vector<int64_t> div(const int64_t n) noexcept {
    std::vector<int64_t> d;
    for(int64_t i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            d.emplace_back(i);
            if(i * i != n) {
                d.emplace_back(n / i);
            }
        }
    }
    std::ranges::sort(d);
    return d;
}
inline int64_t solve() noexcept {
    int64_t a, b;
    std::cin >> a >> b;
    const auto d = div(b - a);
    const auto it = std::ranges::lower_bound(d, a);
    return it == d.cend() ? -1 : *it - a;
}
int main() {
    std::cin.tie(nullptr) -> sync_with_stdio(false);
    int t;
    std::cin >> t;
    while(t--) {
        std::cout << solve() << '\n';
    }
}