QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#738018#9622. 有限小数LmR308WA 58ms3716kbC++172.0kb2024-11-12 17:27:062024-11-12 17:27:07

Judging History

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

  • [2024-11-12 17:27:07]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:3716kb
  • [2024-11-12 17:27:06]
  • 提交

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 <= 50; i++) {
		int te = 1;
		for (int j = 0; j < i; j++) te = te * 2;
		for (int j = 0; j <= 50; j++) {
			if (te >= 1e9 / 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, Te = lc / comd;
				tempc = (tempc % Te + Te) % Te;
				assert(tempc >= 0);
				bool flag = false;
				int sum = a * d + b * tempc;
				if (sum == 0) flag = true;
				if (sum % (b * d) == 0 && sum != 0) flag = true;
				if (sum != 0 && (b * d) % sum == 0) {
					int g = (b * d) / sum;
					while (g % 2 == 0) g /= 2;
					while (g % 5 == 0) g /= 5;
					if (g == 1) flag = true;
				}
				// if (flag) cout << a << " " << b << " " << tempc << " " << d << " " << 1.0 * (a * d + b * tempc) / (b * d) << " aaa\n";
				if (resc > tempc && flag) {
					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: 1ms
memory: 3696kb

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 3
1 14
3 316

result:

ok 4 case(s)

Test #2:

score: -100
Wrong Answer
time: 58ms
memory: 3716kb

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 12
25 53
4557430888798830399 4557430888798830399
1 7
11 1810
43 123
5 282
5 326
28 99
4557430888798830399 4557430888798830399
28 61
4557430888798830399 4557430888798830399
29 122
16 43
2 37
15 143
13 53
9 46
1 31
1 6
9 362
18 91
10 23
10 81
0 1
3 190
4557430888798830399 4557430888798830399
17 166
...

result:

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