QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#740632#9622. 有限小数PHarrWA 0ms3688kbC++20944b2024-11-13 10:48:202024-11-13 10:48:21

Judging History

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

  • [2024-11-13 10:48:21]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3688kb
  • [2024-11-13 10:48:20]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;


using i64 = long long;

const i64 MAXN = 1e9;
const i64 inf = LLONG_MAX / 2;

i64 exgcd(i64 a, i64 b, i64 &x, i64&y) {
	if(b == 0){
		x = 1, y = 0;
		return a;
	}
	i64 d = exgcd(b, a % b, y, x);
	y -= a/ b * d;
	return d;
}

i64 calc(i64 a, i64 b, i64 c) {
	i64 x, y;
	i64 d = exgcd(a, b, x, y);
	if(c % d != 0) return inf;
	x = x * c / d;
	i64 t = b / d;
	return (x % t + t) % t;
}

void solve() {
	i64 a, b;
	cin >> a >> b;

	i64 w = b;
	while(w % 2 == 0) w /= 2;
	while(w % 5 == 0) w /= 5;
	
	if(w == 1) {
		cout << "0 1\n";
		return;
	}

	i64 resc = inf, resd;
	for(i64 p5 = w; p5 <= MAXN; p5 *= 5)
		for(i64 d = p5, c; d <= MAXN; d *= 2) {
			c = calc(b, b * d, a * d);
			if(c < resc) resc = c, resd = d;
		}
	cout << resc << " " << resd << "\n";
	return;
}

int main() {
	int T;
	cin >> T;

	while(T --)
		solve();

	return 0;
}

詳細信息

Test #1:

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

input:

4
1 2
2 3
3 7
19 79

output:

0 1
2 3
3 7
19 79

result:

wrong answer The result is not terminating.(Testcase 2)