結果
問題 |
No.2767 Add to Divide
|
ユーザー |
|
提出日時 | 2024-05-31 21:35:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 512 bytes |
コンパイル時間 | 628 ms |
コンパイル使用メモリ | 65,384 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-20 22:41:59 |
合計ジャッジ時間 | 1,678 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
#include<iostream> #include<cassert> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T;cin>>T; for(;T--;) { int A,B; cin>>A>>B; if(B%A==0) { cout<<"0\n"; continue; } int ansX=B+1; for(int k=2;(k-1)*(k-1)<=B;k++) { long t=B-(long)k*A; if(t>=0&&t%(k-1)==0) { int X=t/(k-1); ansX=min(ansX,X); } } for(int X=0;X*X<=B;X++) { if((B+X)%(A+X)==0)ansX=min(ansX,X); } if(ansX==B+1)cout<<"-1\n"; else cout<<ansX<<"\n"; } }