結果
問題 |
No.2767 Add to Divide
|
ユーザー |
|
提出日時 | 2024-06-01 20:42:55 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 705 bytes |
コンパイル時間 | 3,475 ms |
コンパイル使用メモリ | 251,540 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-22 10:07:31 |
合計ジャッジ時間 | 4,648 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; vector<long long> calc_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i != 0) continue; res.push_back(i); if (N / i != i) res.push_back(N / i); } sort(res.begin(), res.end()); return res; } int main(){ ll t; cin>>t; while(t--){ ll a,b; cin>>a>>b; if(a==b){ cout<<0<<endl; }else{ bool ok=false; vector<ll> dv=calc_divisors(b-a); for(ll d:dv){ if(a<=d){ cout<<d-a<<endl; ok=true; break; } } if(!ok){ cout<<-1<<endl; } } } }