結果

問題 No.2767 Add to Divide
ユーザー VvyLwVvyLw
提出日時 2024-06-01 12:17:24
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 1,899 ms
コンパイル使用メモリ 113,284 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-01 12:17:29
合計ジャッジ時間 2,855 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 30 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 20 ms
6,940 KB
testcase_06 AC 19 ms
6,940 KB
testcase_07 AC 21 ms
6,940 KB
testcase_08 AC 26 ms
6,940 KB
testcase_09 AC 24 ms
6,944 KB
testcase_10 AC 25 ms
6,944 KB
testcase_11 AC 26 ms
6,940 KB
testcase_12 AC 24 ms
6,940 KB
testcase_13 AC 24 ms
6,940 KB
testcase_14 AC 24 ms
6,940 KB
testcase_15 AC 23 ms
6,944 KB
testcase_16 AC 25 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    if(a == b) {
        return 0;
    }
    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';
    }
}
0