結果
問題 |
No.2767 Add to Divide
|
ユーザー |
|
提出日時 | 2024-05-31 22:04:57 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 988 bytes |
コンパイル時間 | 1,403 ms |
コンパイル使用メモリ | 106,340 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-20 23:33:56 |
合計ジャッジ時間 | 2,107 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | WA * 16 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; using ll = long long; constexpr int iINF = 1'000'000'000; constexpr ll llINF = 1'000'000'000'000'000'000; vector<int> divisors (int x) { vector<int> res; for (int i = 1; 1LL * i * i <= x; i++) { if (x % i == 0) res.push_back(i); x /= i; if (1LL * i * i == x) continue; res.push_back(x / i); } sort(res.begin(), res.end()); return res; } void solve (int A, int B) { if (A == 1) { cout << 0 << "\n"; return; } auto d = divisors(B - A); int ans = -1; for (auto v : d) { if (A <= v) { int candi = v - A; if ((B + candi) % (A + candi) == 0) { ans = candi; break; } } } cout << ans << "\n"; } int main () { int T; cin >> T; for (int i = 0; i < T; i++) { int A, B; cin >> A >> B; solve(A, B); } }