QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#497638#6440. Xingqiu's JokepagohiaWA 0ms3596kbC++141.3kb2024-07-29 15:24:332024-07-29 15:24:37

Judging History

你现在查看的是最新测评结果

  • [2024-07-29 15:24:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3596kb
  • [2024-07-29 15:24:33]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
const int N = 305;
typedef long long ll;
typedef double db;
typedef pair<int, int>pii;
typedef pair<long, long>pll;
int n, x, y;
int minn = 0x3ffff;
long long arr[N];
int nowx, nowy;

int check(int a, int b)
{
	if (a == 1 || b == 1) return 1;
	else return 0;
}
bool isPrime(int num) {
	if (num <= 1)
		return false;
	for (int i = 2; i * i <= num; ++i) {
		if (num % i == 0)
			return false;
	}
	return true;
}
int gcd(int a, int b) {
	while (b != 0) {
		int temp = a % b;
		a = b;
		b = temp;
	}
	return a;
}
vector<int> findPrimesGCD(int num1, int num2) {
	vector<int> factors;
	int gcdValue = gcd(num1, num2);
	for (int i = 2; i <= gcdValue; ++i) {
		if (gcdValue % i == 0 && isPrime(i))
			factors.push_back(i);
	}
	return factors;
}

void dfs(int a, int b, int step)
{
	if (check(a, b))
	{
		minn = min(minn, step);
		return;
	}
	if (step > minn)
	{
		return;
	}
	dfs(a - 1, b - 1, step + 1);
	dfs(a + 1, b + 1, step + 1);
	vector<int> commonFactors = findPrimesGCD(a, b);
	for (int factor : commonFactors) {
		dfs(a / factor, b / factor, step + 1);
	}


}

void solve()
{
	int a, b;
	int step = 0;
	cin >> a >> b;
	dfs(a, b, step);
	cout << minn << endl;


}

int main()
{
	int tcase;
	cin >> tcase;
	while (tcase--)
		solve();


}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3596kb

input:

5
4 7
9 8
32 84
11 35
2 1

output:

2
2
2
2
0

result:

wrong answer 2nd numbers differ - expected: '7', found: '2'