結果

問題 No.2767 Add to Divide
ユーザー 乾麺乾麺
提出日時 2024-05-31 21:55:23
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 962 bytes
コンパイル時間 3,759 ms
コンパイル使用メモリ 273,700 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-31 21:55:34
合計ジャッジ時間 4,309 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 13 ms
6,940 KB
testcase_04 WA -
testcase_05 AC 7 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 7 ms
6,940 KB
testcase_08 AC 11 ms
6,940 KB
testcase_09 WA -
testcase_10 AC 12 ms
6,944 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/dsu>
#include <atcoder/segtree>
using namespace atcoder;
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
#define ALL(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define BS(A,x) binary_search(ALL(A),x)
#define LB(A,x) (ll)(lower_bound(ALL(A),x)-A.begin())
#define UB(A,x) (ll)(upper_bound(ALL(A),x)-A.begin())
#define COU(A,x) (UB(A,x)-LB(A,x))
using vi = vector<int>; 
using vvi = vector<vi>; 
using li =vector<ll>;
using lli=vector<li>;
using si =vector<char>;
using ssi =vector<si>;
const long long INF = 1e18;
const long long MOD=1e9+7;
//for (auto [key, val] : mp)
int main() { int t;cin>>t;
while(t--){
	int a,b;cin>>a>>b;
	if(2*a>b)cout<<-1<<endl;
	else if(b==2*a)cout<<0<<endl;
	else{int x=b-2*a;int c=b-a;
		for(int i=1;i*i<=c;i++){
		if(c%i==0&&a<=i)	{	cout<<i-a<<endl;break;}
        else if(c%i==0&&a<=c/i)x=min(x,c/i-a);
		}
		cout<<x<<endl;
	}
}
}
0