結果

問題 No.2767 Add to Divide
ユーザー kotatsugamekotatsugame
提出日時 2024-05-31 21:35:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 512 bytes
コンパイル時間 620 ms
コンパイル使用メモリ 64,508 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-31 21:35:30
合計ジャッジ時間 1,582 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 17 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 15 ms
6,940 KB
testcase_06 AC 15 ms
6,944 KB
testcase_07 AC 14 ms
6,944 KB
testcase_08 AC 15 ms
6,940 KB
testcase_09 AC 15 ms
6,940 KB
testcase_10 AC 15 ms
6,940 KB
testcase_11 AC 35 ms
6,940 KB
testcase_12 AC 33 ms
6,940 KB
testcase_13 AC 33 ms
6,940 KB
testcase_14 AC 32 ms
6,940 KB
testcase_15 AC 31 ms
6,940 KB
testcase_16 AC 32 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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";
	}
}
0