QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#767530 | #9622. 有限小数 | OOBMABTRAMS# | WA | 1ms | 3600kb | C++17 | 758b | 2024-11-20 21:11:58 | 2024-11-20 21:11:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int N=1000013;
typedef long long ll;
const ll inf=1e9;
typedef long double ld;
vector<ll>v;
void solve(){
ll a,b;
cin>>a>>b;
ll e=b;
while(e%2==0)e/=2;
while(e%5==0)e/=5;
if(e==1) {
cout<<1<<' '<<1<<'\n';
return;
}
pair<ll,ll>ans={b-a,b};
//(ak+c)/b
for(auto k:v) {
if(b*k>inf)break;
ll c=a*k%b;
c=(b-c)%b;
ans=min(ans,make_pair(c,b*k));
}
cout<<ans.first<<' '<<ans.second<<'\n';
}
//
signed main(){
for(int i=0;i<=30;i++) {
ll x=1<<i;
while(x<=inf)v.push_back(x),x*=5;
}
sort(v.begin(), v.end());
int T=1;cin>>T;
while(T--) solve();
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3600kb
input:
4 1 2 2 3 3 7 19 79
output:
1 1 1 3 1 14 3 316
result:
wrong answer Jury found better answer than participant's 0 < 1 (Testcase 1)