提出 #35536931


ソースコード 拡げる

#include <bits/stdc++.h>

using namespace std;

void Main()
{
	int A, B;
	cin >> A >> B;
	if (A > B)
	{
		cout << A - B << endl;
		return ;
	}
	long long ans = 1LL << 60;
	for (int x = B; x >= A; x = B / (B / x + 1))
	{
		int y = B / (B / x + 1) + 1;
		int dA = max(y, A) - A, dB = (B + (A + dA) - 1) / (A + dA) * (A + dA) - B;
		ans = min(ans, 0LL + dA + dB);
	}
	auto chk = [&] (int v)
	{
		if (v < A) return ;
		int dA = v - A, dB = (B + (A + dA) - 1) / (A + dA) * (A + dA) - B;
		ans = min(ans, 0LL + dA + dB);
	};
	for (int i = 1; i * i <= B; ++ i)
	{
		if (B % i == 0)
		{
			chk(i);
			chk(B / i);
		}
	}
	cout << ans << endl;
}

int main()
{
	int T;
	cin >> T;
	while (T --) Main();
	return 0;
}

提出情報

提出日時
問題 B - Make Divisible
ユーザ bmb87978
言語 C++ (GCC 9.2.1)
得点 500
コード長 746 Byte
結果 AC
実行時間 76 ms
メモリ 3584 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 1
AC × 24
セット名 テストケース
Sample 00-sample-001.txt
All 00-sample-001.txt, 01-random-001.txt, 01-random-002.txt, 01-random-003.txt, 01-random-004.txt, 01-random-005.txt, 01-random-006.txt, 01-random-007.txt, 01-random-008.txt, 01-random-009.txt, 01-random-010.txt, 01-random-011.txt, 01-random-012.txt, 01-random-013.txt, 01-random-014.txt, 01-random-015.txt, 02-random-001.txt, 02-random-002.txt, 02-random-003.txt, 02-random-004.txt, 02-random-005.txt, 03-test-001.txt, 03-test-002.txt, 03-test-003.txt
ケース名 結果 実行時間 メモリ
00-sample-001.txt AC 7 ms 3412 KiB
01-random-001.txt AC 32 ms 3464 KiB
01-random-002.txt AC 32 ms 3580 KiB
01-random-003.txt AC 30 ms 3300 KiB
01-random-004.txt AC 33 ms 3324 KiB
01-random-005.txt AC 33 ms 3472 KiB
01-random-006.txt AC 70 ms 3364 KiB
01-random-007.txt AC 70 ms 3508 KiB
01-random-008.txt AC 72 ms 3504 KiB
01-random-009.txt AC 76 ms 3352 KiB
01-random-010.txt AC 70 ms 3464 KiB
01-random-011.txt AC 9 ms 3468 KiB
01-random-012.txt AC 8 ms 3468 KiB
01-random-013.txt AC 7 ms 3532 KiB
01-random-014.txt AC 7 ms 3484 KiB
01-random-015.txt AC 10 ms 3468 KiB
02-random-001.txt AC 12 ms 3364 KiB
02-random-002.txt AC 11 ms 3460 KiB
02-random-003.txt AC 11 ms 3332 KiB
02-random-004.txt AC 10 ms 3464 KiB
02-random-005.txt AC 12 ms 3508 KiB
03-test-001.txt AC 10 ms 3508 KiB
03-test-002.txt AC 2 ms 3584 KiB
03-test-003.txt AC 2 ms 3352 KiB