結果
問題 | No.2767 Add to Divide |
ユーザー | Ywestbuilderk |
提出日時 | 2024-05-31 23:17:53 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 412 bytes |
コンパイル時間 | 2,426 ms |
コンパイル使用メモリ | 201,920 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-21 01:35:03 |
合計ジャッジ時間 | 3,126 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ int t; cin >> t; for(int i = 0;i < t;i++){ int a,b; cin >> a >> b; int c = b - a; if(b == a) cout << 0 << endl; else if(c < a) cout << -1 << endl; else{ int ans = c; for(int j = 1;j * j <= c;j++){ if(c % j == 0){ if(j >= a) ans = min(ans,j); if(c / j >= a) ans = min(ans,c / j); } } cout << ans - a << endl; } } }