結果
問題 | No.2767 Add to Divide |
ユーザー |
![]() |
提出日時 | 2024-05-31 21:46:50 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 143 ms / 2,000 ms |
コード長 | 586 bytes |
コンパイル時間 | 2,208 ms |
コンパイル使用メモリ | 200,388 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-20 23:03:38 |
合計ジャッジ時間 | 4,520 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
#include<bits/stdc++.h>using namespace std;int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int T;cin>>T;while(T--){long A,B;cin>>A>>B;int ans=1<<30;for(int X=0;X<=100000;X++)if((B+X)%(A+X)==0){ans=X;break;}for(int k=2;B-k*A>=0&&k<=100000;k++){if((B-k*A)%(k-1)==0){int X=(B-k*A)/(k-1);ans=min(ans,X);}}if(ans==1<<30)ans=-1;cout<<ans<<'\n';}}