結果
問題 |
No.2767 Add to Divide
|
ユーザー |
|
提出日時 | 2024-05-31 23:25:15 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 843 bytes |
コンパイル時間 | 4,204 ms |
コンパイル使用メモリ | 280,716 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-21 01:41:28 |
合計ジャッジ時間 | 5,347 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
#include<bits/stdc++.h> using namespace std; const long long INF = 1e18; vector<long long> factorize(long long d) { vector<long long> res; for (long long j = 1; j * j <= d; j++) { if (d % j == 0) { res.push_back(j); res.push_back(d / j); } } return res; } int main() { int T; cin >> T; while (T--) { long long A, B; cin >> A >> B; if (A == B) { cout << 0 << '\n'; continue; } long long d = B - A; vector<long long> c = factorize(d); sort(c.begin(), c.end()); int N = c.size(); long long ans = INF; for (int i = 0; i < N; i++) { if (c[i] < A) continue; long long d = c[i] - A; int a = A + d; int b = B + d; if (b % a == 0) { ans = min(ans, d); } } if (ans == INF) ans = -1; cout << ans << '\n'; } }