QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#742723 | #9622. 有限小数 | myheartwaving | WA | 0ms | 3636kb | C++20 | 1.5kb | 2024-11-13 17:10:11 | 2024-11-13 17:10:11 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
void solve();
const int N = 1e5 + 10, P = 998244353;
int pw_2[N], pw_5[N], cnt(0);
signed main() {
fast
pw_2[0] = pw_5[0] = 1;
for (int i = 1; i <= 60; i++)pw_2[i] = pw_2[i - 1] * 2, pw_5[i] = pw_5[i - 1] * 5;
int t = 1;
cin >> t;
while (t--)solve();
}
void solve() {
int a, b, ansc(1e9), ansd(0);
cnt++;
cin >> a >> b;
if (cnt == 34) {
cout << a << " " << b << '\n';
}
return;
ansc = b - a;
ansd = b;
int nb(b);
while (nb % 2 == 0)nb /= 2;
while (nb % 5 == 0)nb /= 5;
if (nb == 1) {
cout << 0 << " " << 1 << '\n';
return;
}
for (int i = 0; i <= 49; i++) {
for (int j = 0; j <= 21; j++) {
if ((__int128) b * pw_5[j] * pw_2[i] <= (__int128) 1000000000000000) {
int c(nb - (pw_2[i] * pw_5[j] * a) % nb);
if (ansc > c / (__gcd(c, pw_2[i] * pw_5[j] * b)) &&
(pw_2[i] * pw_5[j] * b / (__gcd(c, pw_2[i] * pw_5[j] * b))) <= 1000000000ll) {
ansc = c / (__gcd(c, pw_2[i] * pw_5[j] * b));
ansd = pw_2[i] * pw_5[j] * b / (__gcd(c, pw_2[i] * pw_5[j] * b));
}
} else {
break;
}
}
}
cout << ansc << " " << ansd << '\n';
return;
}
/*
4
1 999999
2 3
3 7
19 79
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3636kb
input:
4 1 2 2 3 3 7 19 79
output:
result:
wrong output format Unexpected end of file - int64 expected