結果
問題 |
No.2767 Add to Divide
|
ユーザー |
![]() |
提出日時 | 2024-06-01 13:29:27 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 2,000 ms |
コード長 | 670 bytes |
コンパイル時間 | 686 ms |
コンパイル使用メモリ | 77,584 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-21 21:37:35 |
合計ジャッジ時間 | 1,597 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
#include <iostream> using namespace std; using ll = long long; const int inf = 2e9; // B + X = k(A + X) // B - A = (k - 1)(A + X) int A, B; void solve(){ cin >> A >> B; if(A == B){ cout << 0 << "\n"; return; } int N = B - A; int ans = inf; for(int i = 1;i * i <= N;i++){ if(N % i != 0)continue; if(i >= A){ ans = min(ans, i - A); } if(N / i >= A){ ans = min(ans, N / i - A); } } cout << (ans == inf ? -1 : ans) << "\n"; } int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while(t--)solve(); return 0; }