結果
問題 |
No.2767 Add to Divide
|
ユーザー |
|
提出日時 | 2024-05-31 21:32:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 505 bytes |
コンパイル時間 | 1,650 ms |
コンパイル使用メモリ | 64,096 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-20 22:33:36 |
合計ジャッジ時間 | 1,929 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 WA * 8 |
ソースコード
#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++) { int t=B-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"; } }