QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#737776#9622. 有限小数LmR308WA 66ms3728kbC++171.5kb2024-11-12 16:50:162024-11-12 16:50:18

Judging History

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

  • [2024-11-12 16:50:18]
  • 评测
  • 测评结果:WA
  • 用时:66ms
  • 内存:3728kb
  • [2024-11-12 16:50:16]
  • 提交

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 <= 40; i++) {
		int te = 1;
		for (int j = 0; j < i; j++) te = te * 2;
		for (int j = 0; j <= 40; j++) {
			if (te >= 1e14 / temp) 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: 3728kb

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: 66ms
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
1 828125000
-2 15
3 21875
1 231680000
23 3753662109375
1 2203125000
1 2608000000000
1 63360
0 1
1 744628906250
0 1
1 59570312500
-882 172
-648 1445312500
1 1117187500
1 331250
1 140380859375
1 31
-2 15
1 289600000
1 455000
1 35095214843750
1 1265625
0 1
-162 2375
0 1
1 415
1 235937500
1 18676757...

result:

wrong answer Integer -2 violates the range [0, 10^9]