QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#740014 | #9622. 有限小数 | TLE_Automat | WA | 0ms | 3720kb | C++20 | 1.9kb | 2024-11-13 00:19:47 | 2024-11-13 00:19:47 |
Judging History
answer
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define SZ(x) ((int)((x).size()))
#define lb(x) ((x) & (-(x)))
#define bp(x) __builtin_popcount(x)
#define bpll(x) __builtin_popcountll(x)
#define mkp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef __gnu_pbds::tree<pii, null_type, less<pii>, __gnu_pbds::rb_tree_tag,
__gnu_pbds::tree_order_statistics_node_update> rbt;
const int N = 1e9;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1;
y = 0;
return a;
}
ll g = exgcd(b, a % b, x, y);
ll tmp = x; x = y;
y = tmp - a / b * y;
return g;
}
void solve() {
ll a, b;
cin >> a >> b;
ll m = b;
while (m % 2 == 0) {
m /= 2;
}
while (m % 5 == 0) {
m /= 5;
}
ll ansc = 1e18, ansd = 1e18;
for (ll tmp = m; tmp <= N; tmp *= 2) {
for (ll d = tmp; d <= N; d *= 5) {
// ad + bc = k(m^2)
// b * [-c] + (m^2) * [k] = ad
ll c, k;
ll g = exgcd(b, m * m, c, k);
if (a * d % g != 0) {
continue;
}
c *= a * d / g;
k *= a * d / g;
ll stp = m * m / g;
c = (c % stp + stp) % stp;
c -= stp;
if ((a * d - b * c) / (m * m) <= 0) {
continue;
}
if (ansc > -c) {
ansc = -c;
ansd = d;
}
}
}
cout << ansc << " " << ansd << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3720kb
input:
4 1 2 2 3 3 7 19 79
output:
1 1 1 3 1 4375 3 316
result:
wrong answer Jury found better answer than participant's 0 < 1 (Testcase 1)