QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#790378#9622. 有限小数LonelyperWA 0ms3696kbC++141.0kb2024-11-28 11:19:052024-11-28 11:19:06

Judging History

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

  • [2024-11-28 11:19:06]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3696kb
  • [2024-11-28 11:19:05]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
#define int long long

const int N = 1e18 + 10;

int a, b;


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

int cal(int a, int b, int c){
	int x, y;
	int d = exgcd(a, b, x, y);
	x = x * c / d;
	int t = abs(b / d);
	return (x % t + t) % t;
}

void WTF()
{
	cin >> a >> b;
	int w = b;
	while(w % 2 == 0) w /= 2;
	while(w % 5 == 0) w /= 5;
	if(w == 1){
		cout << "0 1" << endl;
		return;
	}
	int ansc = 1e18 + 10, ansd = 1e18 + 10;
	for(int i = w; i <= N; i *= 2){
		for(int d = i; d <= N; d *= 5){
			int c = cal(b,  - (w * w), - (a * d));
//			cout << c << ' ' << d << endl;
//			int g = __gcd(c, d);
//			if(g != 0) c /= g, d /= g;
			if(c < ansc){
				ansc = c;
				ansd = d;
			}
		}
	}
	cout << ansc << ' ' << ansd << endl;
}

signed main()
{
	int t = 1;
	cin>>t;
	while(t --)
	{
		WTF();
	}

	return 0;
}


详细

Test #1:

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

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 3
1 4375
3 1506805419921875

result:

wrong answer Integer 1506805419921875 violates the range [1, 10^9]