QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#763809 | #9622. 有限小数 | xdz_ | WA | 0ms | 3712kb | C++20 | 1.0kb | 2024-11-19 22:11:09 | 2024-11-19 22:11:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define se second
#define fi first
#define endl '\n'
const int N = 1e5 + 10;
bool pan(int x){
while(x % 2 == 0) x /= 2;
while(x % 5 == 0) x /= 5;
if(x == 1) return 1;
}
void solve(){
int a,b;
cin>>a>>b;
int w = pan(b);
if(w == 1){
cout<<"0 1"<<endl;
return ;
}
int ma = 1e9 / b;
int er = 1;
set<int> res1;
while(er < ma){
int wu = 1;
for(int i = 0;i <= 100;i ++){
if(i > 0) wu *= 5;
int k = er * wu;
if(k > ma) break;
else res1.insert(k);
}
er *= 2;
}
vector<int> res;
for(auto k : res1) res.push_back(k);
int c = b - a,d = b;
// cout<<c<<endl;
for(auto x : res){
int jian = a * x;
int k = jian / b;
if(k * b < jian) k ++;
if(b * k - jian < c){
c = b * k - jian;
d = x * b;
// cout<<x<<" "<<b<<endl;
}
}
cout<<c<<" "<<d<<endl;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3712kb
input:
4 1 2 2 3 3 7 19 79
output:
0 1 0 1 0 1 0 1
result:
wrong answer The result is not terminating.(Testcase 2)