結果
問題 | No.2767 Add to Divide |
ユーザー | srjywrdnprkt |
提出日時 | 2024-02-29 17:12:16 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 52 ms / 2,000 ms |
コード長 | 593 bytes |
コンパイル時間 | 2,059 ms |
コンパイル使用メモリ | 201,344 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-14 18:49:43 |
合計ジャッジ時間 | 3,328 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const int M = 31623; void solve(){ ll A, B, mi=2e9; cin >> A >> B; for (int X=0; X<=M; X++){ if ((B+X) % (A+X) == 0){ mi = X; break; } } for (int Y=2; Y<=M; Y++){ if (B-A*Y >= 0 && (B-A*Y) % (Y-1) == 0) mi = min(mi, (B-A*Y) / (Y-1)); } if (mi == 2e9) cout << -1 << '\n'; else cout << mi << '\n'; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int T; cin >> T; while(T--) solve(); return 0; }