QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#738275 | #9622. 有限小数 | huo_hua_ya | WA | 16ms | 3712kb | C++23 | 1.2kb | 2024-11-12 18:29:25 | 2024-11-12 18:29:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 7;
const int mod = 998244353;
std::vector<int> vc;
void solve()
{
ll a, b;
cin >> a >> b;
a%=b;
ll p = b, k = 1;
while (p % 2 == 0) {
p /= 2;
k *= 2;
}
while (p % 5 == 0) {
p /= 5;
k *= 5;
}
ll c=b-a,d=b;
for(auto it:vc)
{
ll tmp=it*b;
if(tmp>1000000000)continue;
ll fz=a*it;
int l=0,r=vc.size();
r--;
ll ans=-1;
while(l<=r)
{
ll mid=l+r>>1;
if(vc[mid]*p>=fz)
{
ans=mid;
r=mid-1;
}
else l=mid+1;
}
if(vc[ans]*p-fz<=c)
{
c=vc[ans]*p-fz;
d=it*b;
}
}
cout<<c<<' '<<d<<endl;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
for(ll now=1;now<=1000000000;now*=2)
for(ll tmp=1;tmp*now<=1000000000;tmp*=5)
{
vc.push_back(now*tmp);
}
sort(vc.begin(),vc.end());
int _ = 1;
cin >> _;
while (_--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3700kb
input:
4 1 2 2 3 3 7 19 79
output:
0 1000000000 1 3 1 14 3 316
result:
ok 4 case(s)
Test #2:
score: -100
Wrong Answer
time: 16ms
memory: 3712kb
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 7 240 3 560 11 1810 43 123 5 282 5 326 28 99 3 64 28 61 1 32 29 122 1 10750 4 74 15 143 12 265 3 368 1 31 1 6 9 362 18 91 10 23 10 81 0 1000000000 3 190 8 160 1 415 22 151 61 1224 4 58 3 19 46 705 15 992 5 96 21 17375 4 295 3 109 2 152 2 215 14 495 7 2850 44 19875 0 1000000000 21 1825 11 ...
result:
wrong answer Jury found better answer than participant's 1 < 25 (Testcase 2)