結果
問題 | No.2767 Add to Divide |
ユーザー |
|
提出日時 | 2024-05-31 22:02:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 785 bytes |
コンパイル時間 | 1,739 ms |
コンパイル使用メモリ | 192,204 KB |
最終ジャッジ日時 | 2025-02-21 17:52:56 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | TLE * 1 -- * 15 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;int main(){ios::sync_with_stdio(false);cin.tie(0);int T;cin >> T;while(T--){ll a, b;cin >> a >> b;if(b % a == 0){cout << 0 << '\n';continue;}ll c = b / a;if(c == 1){cout << -1 << '\n';continue;}// c 倍以下は確定// A * k == B// (a + x) * k == (b + x)// a + (k - 1) * x == b// b - a == (k - 1) * xll ans = -1;for(ll i = c; i >= 2; i--){if((b - a * i) % (i - 1) == 0){ans = (b - a * i) / (i - 1);break;}}cout << ans << '\n';}}