結果
問題 | No.2767 Add to Divide |
ユーザー |
![]() |
提出日時 | 2024-05-31 21:43:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 816 bytes |
コンパイル時間 | 1,987 ms |
コンパイル使用メモリ | 196,260 KB |
最終ジャッジ日時 | 2025-02-21 17:40:43 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9 + 10; const ll INFL = 4e18; int main() { int T; cin >> T; while (T--) { ll A, B; cin >> A >> B; vector<ll> divisors; for (ll i = 1; i * i <= B - A; i++) { if ((B - A) % i == 0) { divisors.push_back(i); if (i * i != B - A) divisors.push_back((B - A) / i); } } if (B == A) { cout << 0 << endl; continue; } ll ans = INFL; for (ll d : divisors) { if (d >= A) { ans = min(ans, d - A); } } if (ans == INFL) { cout << -1 << endl; } else { cout << ans << endl; } } }