QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#737888 | #9622. 有限小数 | LmR308 | WA | 111ms | 3724kb | C++17 | 1.8kb | 2024-11-12 17:04:00 | 2024-11-12 17:04:00 |
Judging History
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 >= 1e16 / 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;
assert(m >= 0);
bool flag = false;
int sum = a * d + b * tempc;
if (sum % (b * d) == 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 (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: 3724kb
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: 111ms
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 -2 60 3 70 11 1810 43 123 5 282 5 326 28 99 4557430888798830399 4557430888798830399 28 61 4557430888798830399 4557430888798830399 29 122 -882 172 4557430888798830399 4557430888798830399 15 143 13 53 9 46 1 31 -2 6 9 362 18 91 10 23 10 81 0 1 -144 2432 4557430888798830399 45574308887988303...
result:
wrong answer Jury found better answer than participant's 1 < 25 (Testcase 2)