QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#744714#9622. 有限小数dmrmra#WA 1ms3552kbC++111.6kb2024-11-13 22:59:112024-11-13 22:59:16

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 22:59:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3552kb
  • [2024-11-13 22:59:11]
  • 提交

answer

//
// Created by 16373 on 2024/11/13.
//
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353,inf=1e18;
int qpow(int a,int x){
    int res=1;
    while(x){
        if(x&1) res=res*a;
        x>>=1;
        a*=a;
    }
    return res;
}
void solve(){
    int a,b;
    cin>>a>>b;
    int prime=b;
    int cnt2=0,cnt5=0;
    while(prime%2==0){
        cnt2++;
        prime/=2;
    }
    while(prime%5==0){
        cnt5++;
        prime/=5;
    }
    int pw2=qpow(2,cnt2),pw5=qpow(5,cnt5);
    int now2=1;
    unordered_map<int,pair<int,int>> mp;
    for(int i=0;prime*now2*pw2*pw5<=inf;i++,now2*=2){
        int now=now2;
        for(int j=0;prime*now*pw2*pw5<=inf;j++,now*=5){
            int md=a*now%prime;
            int ans=(prime-md)%prime;
//            cout<<i<<' '<<j<<' '<<ans<<'\n';
            if(!mp.count(ans)){
                mp[ans]={i,j};
            }
        }
    }
    int c=inf,d;
    for(auto e:mp){
        int pre=e.first;
        auto sub=e.second;
        int n2=sub.first,n5=sub.second;
//        cout<<n2<<' '<<n5<<'\n';
        int nc=pre,nd=prime*pw2*pw5*qpow(2,n2)*qpow(5,n5);
        int gc=__gcd(nc,nd);
        nc/=gc;  nd/=gc;
        if(nd<=(int)1e9 && nc<c){
//            cout<<nc<<' '<<nd<<'\n';
            c=nc; d=nd;
        }
    }
    cout<<c<<' '<<d<<'\n';
}
signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
//2
//630
//3029 2336 377 41 10 61
//3000
//20000 10000 0 0 0 0

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3552kb

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 3
1 4375
6 154296875

result:

wrong answer Jury found better answer than participant's 3 < 6 (Testcase 4)