QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#231849#6440. Xingqiu's JokezGoofy#WA 0ms3512kbC++14977b2023-10-29 17:09:482023-10-29 17:09:48

Judging History

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

  • [2023-10-29 17:09:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3512kb
  • [2023-10-29 17:09:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

map<pair<int, int>, int>mp;
vector<int>cnt;
int dfs(int a, int t) {
    if(a == 1) return 0;
    if(t == 1) return a - 1;
    if(mp[{a, t}]) return mp[{a, t}];
    int res = a - 1;
    for(auto i : cnt) {
        if(t % i == 0) {
            int tmp = dfs(a / i, t / i) + a % i + 1;
            int tmp2 = dfs(a / i + 1, t / i ) + i - (a % i) + 1;
            res = min({tmp, tmp2, res});
        }
    }
    mp[{a, t}] = res;
    return res;
}

void solve() {
	int a, b;
	cin >> a >> b;
	if (a > b) {
		swap(a, b);
	}
	int t = b - a;
	for (int i = 2; i <= t; i++) {
		if (t % i == 0) {
			cnt.push_back(i);
			while (t % i == 0) {
				t /= i;
			}
		}
	}
	if (t != 1) {
		cnt.push_back(t);
	}
	cout << dfs(a, b - a) << endl;
	return;
}




signed main() {
	ios::sync_with_stdio(false);
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
	}
}




Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
4 7
9 8
32 84
11 35
2 1

output:

3

result:

wrong answer 1st numbers differ - expected: '2', found: '3'