QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#738153 | #9622. 有限小数 | ucup-team059# | TL | 1ms | 3784kb | C++20 | 1.1kb | 2024-11-12 17:56:08 | 2024-11-12 17:56:09 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
void solve(){
int a, b;
std::cin >> a >> b;
std::vector<ll> num;
if (b == 5 || b == 2){
std::cout << "0 1\n";
return;
}
constexpr int MAX = 1e6;
for (ll i = 1; i <= MAX; i *= 2){
for (ll j = 1; i * j <= MAX; j *= 5){
for (ll k = 1; i * k * j <= MAX; k *= b){
num.push_back(i * k * j);
}
}
}
std::sort(num.begin(), num.end());
std::pair<ll, ll> ans = {1e18, 1e18};
for (auto d : num){
// std::cout << d << '\n';
ll num1 = a * d;
if (num1 % b == 0){
ll by = b;
ll t = d;
while (t % b == 0){
by *= b;
t /= b;
}
ll add = by;
while ((by - num1) % b && by >= num1){
by += add;
}
by -= num1;
by /= b;
if (ans > std::make_pair(by, d) && by >= 0){
ans = std::make_pair(by, d);
}
}
}
std::cout << ans.first << ' ' << ans.second << '\n';
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3784kb
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
Time Limit Exceeded
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...