結果
問題 | No.2767 Add to Divide |
ユーザー |
|
提出日時 | 2024-05-31 22:08:20 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 1,038 bytes |
コンパイル時間 | 1,331 ms |
コンパイル使用メモリ | 106,204 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-20 23:39:00 |
合計ジャッジ時間 | 2,627 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 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);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;}if (A == B) {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);}}