結果
| 問題 |
No.2767 Add to Divide
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-01 12:17:24 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 2,000 ms |
| コード長 | 787 bytes |
| コンパイル時間 | 4,612 ms |
| コンパイル使用メモリ | 113,500 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-21 18:53:00 |
| 合計ジャッジ時間 | 2,862 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 16 |
ソースコード
#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';
}
}