QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#737741#9622. 有限小数LmR308WA 7ms3708kbC++171.5kb2024-11-12 16:45:372024-11-12 16:45:40

Judging History

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

  • [2024-11-12 16:45:40]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3708kb
  • [2024-11-12 16:45:37]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int128 __int128_t
#define int long long
#define PII pair<int, int>
#define PDD pair<double, double>
#define fi first    
#define se second
#define lowbit(x) x & -x
#define all(x) x.begin(), x.end()
#define INF 0x3f3f3f3f3f3f3f3f
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define ull unsigned long long
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 10, M = 5e6 + 10, mod = 998244353;
const double eps = 1e-8;

int t, n, m, k;	
string sr;

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

void solve() {
	int a, b;
	cin >> a >> b;
	int temp = b;
	while (temp % 2 == 0) temp /= 2;
	while (temp % 5 == 0) temp /= 5;
	int resc = INF, resd = INF, tlc = b / temp;
	for (int i = 0; i <= 30; i++) {
		int te = 1;
		for (int j = 0; j < i; j++) te = te * 2;
		for (int j = 0; j <= 30; j++) {
			if (te * temp >= 1e4) break;
			int d = te * temp;
			int lc = temp * temp, x, y;
			int comd = exgcd(b, lc, x, y), m = (-a * d % lc + lc) % lc;
			if (m % comd == 0) {
				int tempc = m / comd * x;
				if (resc > tempc) {
					resc = tempc;
					resd = d;
				}
			}
			te *= 5;
		}
	}
	cout << resc << " " << resd << "\n";
}

signed main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	cout.setf(ios::fixed), cout.precision(10);
	t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}	

详细

Test #1:

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

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: 7ms
memory: 3660kb

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
5 1696
-2 15
3 70
11 1810
23 3936
5 282
5 326
5 3168
0 1
11 1220
0 1
1 4880
-882 172
-612 2368
7 1430
7 1325
1 2944
1 31
-2 15
9 362
15 1456
3 7360
7 2025
0 1
-162 2375
0 1
1 415
22 151
19 765
-364 1450
1 608
37 7050
24 6200
-2 3
32 3475
1 944
3 109
-126 4864
2 215
1 6336
7 2850
59 795
0 1
11 73...

result:

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