結果
問題 |
No.2767 Add to Divide
|
ユーザー |
|
提出日時 | 2024-08-15 23:10:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 66 ms / 2,000 ms |
コード長 | 928 bytes |
コンパイル時間 | 1,291 ms |
コンパイル使用メモリ | 114,496 KB |
最終ジャッジ日時 | 2025-02-23 22:47:49 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
#include<iostream> #include<string> #include<queue> #include<vector> #include<cassert> #include<random> #include<set> #include<map> #include<cassert> #include<unordered_map> #include<bitset> #include<numeric> #include<algorithm> using namespace std; typedef long long ll; const int inf=1<<30; const ll INF=1LL<<62; typedef pair<int,ll> P; typedef pair<int,P> PP; const ll MOD=998244353; ll solve(){ ll A,B; cin>>A>>B; ll d=B-A; if(d==0){ return 0; } ll C=INF; for(ll m=1;m*m<=d;m++){ if(d%m==0){ if(m>=A){ C=min(C,m); } if(d/m>=A){ C=min(C,d/m); } } } if(C==INF){ return -1; } return C-A; } int main(){ int T; cin>>T; vector<ll> ans(T); for(int t=0;t<T;t++){ ans[t]=solve(); } for(int t=0;t<T;t++){ cout<<ans[t]<<endl; } }