結果
問題 | No.2767 Add to Divide |
ユーザー |
|
提出日時 | 2024-05-31 22:35:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 745 bytes |
コンパイル時間 | 1,822 ms |
コンパイル使用メモリ | 171,516 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-21 00:20:11 |
合計ジャッジ時間 | 2,838 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int,int> P;#define REP(i,n) for(int i=0;i<int(n);i++)vector<int> div(int n){vector<int> d;for(int i=1;i*i<=n;i++){if(n%i==0){d.push_back(i);if(i!=n/i) d.push_back(n/i);}}return d;}int main(void){cin.tie(nullptr); ios_base::sync_with_stdio(false);int T;cin >> T;while(T--){int A,B;cin >> A >> B;B=B-A;if(B==0){cout << 0 << endl;continue;}vector<int> v=div(B);int mn=1e9+10;bool f=false;int n=v.size();REP(i,n){if(v[i]-A<0) continue;else{f=true;mn=min(mn,v[i]-A);}}if(f) cout << mn << endl;else cout << -1 << endl;}return 0;}