QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#790365#9622. 有限小数LonelyperWA 11ms3684kbC++14914b2024-11-28 11:12:232024-11-28 11:12:24

Judging History

This is the latest submission verdict.

  • [2024-11-28 11:12:24]
  • Judged
  • Verdict: WA
  • Time: 11ms
  • Memory: 3684kb
  • [2024-11-28 11:12:23]
  • Submitted

answer

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 1e6 + 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 = 1e9, ansd = 1e9;
	for(int i = w; i <= N; i *= 2){
		for(int d = i; d <= N; d *= 5){
			int c = cal(b,  - (w * w), - (a * d));
			if(c < ansc){
				ansc = c;
				ansd = d;
			}
		}
	}
	cout << ansc << ' ' << ansd << endl;
}

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

	return 0;
}


詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 3
1 4375
3 316

result:

ok 4 case(s)

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 3684kb

input:

10000
11 12
28 53
17 60
2 35
17 181
80 123
68 141
79 163
71 99
13 64
33 61
15 32
16 61
11 86
33 74
128 143
40 53
7 23
30 31
5 6
86 181
73 91
13 23
71 81
1 2
7 38
117 160
33 83
129 151
88 153
25 58
16 19
19 141
95 124
43 96
71 139
11 59
106 109
93 152
34 43
17 99
1 57
20 159
16 25
5 73
159 170
172 17...

output:

1 3
1 54272
1 15
1 7
7 90500
23 246000
5 282
5 326
1 63360
0 1
1 61000
0 1
1 4880
1 10750
1 18500
7 1430
1 331250
1 460000
1 31
1 15
7 113125
1 455000
1 736000
1 51840
0 1
1 304
0 1
1 415
9 94375
5 156672
1 181250
1 608
1 72192
3 775
1 3
3 347500
1 944
1 340625
1 76
1 430000
1 6336
1 29184
11 795000...

result:

wrong answer Jury found better answer than participant's 1 < 7 (Testcase 5)