QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#756759#9622. 有限小数proking#WA 6ms3648kbC++142.2kb2024-11-16 21:50:122024-11-16 21:50:13

Judging History

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

  • [2024-11-16 21:50:13]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3648kb
  • [2024-11-16 21:50:12]
  • 提交

answer

#include <bits/stdc++.h>

#define F(i, a, b) for (ll i = a; i <= b; i ++)
#define G(i, a, b) for (ll i = a; i >= b; i --)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define mx(a, b) ((a) = max(a, b))
#define mn(a, b) ((a) = min(a, b))
#define get getchar()
#define putc putchar

using namespace std;

template <typename ll>
void R(ll &x) {
	char c = get; x = 0; ll t = 1;
	for (; !isdigit(c); c = get) t = (c == '-' ? -1 : t);
	for (; isdigit(c); x = (x << 3) + (x << 1) + c - '0', c = get); x *= t;
}
template <typename ll>
void W(ll x) {
	if (x < 0) { putc('-'); x = - x; }
	if (x > 9) W(x / 10); putc(x % 10 + '0');
}

#define pb push_back
#define ll long long

ll T, a, b, c, d;


ll gcd(ll x, ll y) { return !y ? x : gcd(y, x % y); }
bool ok(ll a, ll b, ll c, ll d) {
	ll fm = b * d / gcd(b, d);
	ll fz = a * fm / b + c * fm / d;
	fm /= gcd(fm, fz);
	while (fm % 2 == 0) fm /= 2;
	while (fm % 5 == 0) fm /= 5;
	return fm == 1;
}

int main() {
//	freopen("data.in","r",stdin);
	
	for (R(T); T --; ) {
		R(a), R(b); ll b_ = b, cnt1 = 0, cnt2 = 0;
		while (b % 2 == 0) b /= 2, cnt1 ++;
		while (b % 5 == 0) b /= 5, cnt2 ++;
		if (b == 1) {
			puts("0 1");
			continue;
		}
		ll s = 1, c = 1e9;
		F(x, 0, 30) {
			ll t = s;
			F(y, 0, 13) {
				if (t > 1e9 / b_) break;
				ll k = (a * t - 1) / b + 1;

				if (k * b - a * t < c)
					c = k * b - a * t, d = b_ * t;

				t = t * 5;
			}
			s = s * 2;
		}
		
		
		int bz = 0;
		F(w, 1, c - 1) {
			s = 1;
			F(x, 0, 30) {
				ll t = 1;
				if (b_ * s > 1e9) break;
				F(y, 0, cnt2) {
					if ( (w * t + a * s) % b == 0)
						bz = 1, c = w, d = b_ * s;
					t = t * 5;
				}
				s = s * 2;
			}
			if (bz) break;
		}
		
		bz = 0;
		F(w, 1, c - 1) {
			s = 1;
			F(x, 0, 13) {
				ll t = 1;
				if (b_ * s > 1e9) break;
				F(y, 0, cnt1) {
					if ( (w * t + a * s) % b == 0)
						bz = 1, c = w, d = b_ * s;
					t = t * 2;
				}
				s = s * 5;
			}
			if (bz) break;
		}

//		if (!ok(a, b_, c, d)) {
//			printf("%d %d %d %d\n", a, b_, c, d);
//			puts("Wrong");
//			return 0;
//		}
		W(c), putc(' '), W(d);
		putc('\n');
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
1 828125000
1 60
1 109375
1 231680000
23 960937500
1 36096000
5 326
1 63360
0 1
1 61000
0 1
1 4880
1 10750
1 18500
1 11714560
1 331250
1 898437500
1 31
1 6
1 289600000
1 455000
1 115000000
1 1265625
0 1
1 29687500
0 1
1 415
1 235937500
1 765000000
1 181250
1 2968750
1 4406250
3 24800
1 480
3 34...

result:

wrong answer The result is not terminating.(Testcase 321)