結果
問題 | No.2767 Add to Divide |
ユーザー | Carpenters-Cat |
提出日時 | 2024-05-31 22:25:28 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 414 bytes |
コンパイル時間 | 2,405 ms |
コンパイル使用メモリ | 199,728 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-21 00:02:33 |
合計ジャッジ時間 | 3,205 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main () { int T; cin >> T; while (T--) { int a, b; cin >> a >> b; if (b % a == 0) { puts("0"); } else { int d = b - a; int p = d; for (int x = 2; x * x <= d; x ++) { if (d % x == 0) { if (a <= x) { p = x; break; } if (a <= d / x) { p = d / x; } } } cout << max(-1, p - a) << endl; } } }