QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#740837 | #9622. 有限小数 | Aicu123 | WA | 30ms | 3712kb | C++20 | 1.8kb | 2024-11-13 11:47:12 | 2024-11-13 11:47:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define fi first
#define se second
//cout<<setiosflags(ios::fixed)<<setprecision(K);
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};
const double eps=1e-9;
const double PI=acos(-1.0);
const int inf=1e9+7;
const int mod=998244353;
const int N=2e5+10,M=N<<1;
#define int long long
vector<int>v;
void init(){
int b=1;
for(int i=0;i<=30;i++){
int c=1;
for(int j=0;j<20&&b*c<=1e9;j++){
int t=b*c;
if(t<=1e9) v.push_back(t);
c*=5;
}
b*=2;
}
sort(v.begin(),v.end());
}
ll gcd(ll a,ll b){
if(b==0) return a;
return gcd(b,a%b);
}
//d为gcd(a,b)
ll exgcd(ll a,ll b,ll &x,ll &y){
if(b==0){
x=1,y=0;
return a;
}
ll x1,y1,d;
d=exgcd(b,a%b,x1,y1);
x=y1,y=x1-a/b*y1;
return d;
}
void solve(){
int a,b;
cin>>a>>b;
int t=1;
while(b%5==0) b/=5,t*=5;
while(b%2==0) b/=2,t*=2;
if(b==1){
cout<<0<<' '<<1<<'\n';
return;
}
int c=b-a%b;
int cd=b*t;
//cerr<<c<<' '<<cd<<'\n';
for(auto x:v){
int d=x*b;
if(d>1e9) continue;
//ax+ct/b
int y;
if(a*x%b==0) y=0;
else y=b-a*x%b;
int cur=0;
int n,m;
int rd=exgcd(t,b,n,m);
if(y%rd==0){
int rc=n*y/rd%b;
if(rc<=c){
c=rc;
cd=d;
}
}
}
cout<<c<<' '<<cd<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
init();
int T=1;
cin>>T;
while(T--){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
input:
4 1 2 2 3 3 7 19 79
output:
0 1 1 805306368 1 896000000 3 161792000
result:
ok 4 case(s)
Test #2:
score: -100
Wrong Answer
time: 30ms
memory: 3628kb
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 805306368 1 828125000 -2 983040000 1 939524096 1 231680000 23 960937500 1 36096000 5 326 1 633600000 0 1 1 61000 0 1 1 4880 -42 721420288 -36 757760000 1 11714560 1 53000000 1 942080000 1 496000000 -2 983040000 1 289600000 1 455000 1 120586240 1 331776000 0 1 -18 972800000 0 1 1 25937500 1 2359375...
result:
wrong answer Integer -2 violates the range [0, 10^9]