QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#739723#9310. Permutation Counting 4liubw_WA 0ms3564kbC++111.6kb2024-11-12 22:50:472024-11-12 22:50:48

Judging History

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

  • [2024-11-12 22:50:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3564kb
  • [2024-11-12 22:50:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define int ll

const int inf=1E18+10;

void exgcd(int a,int b,int &x,int &y){
    if(b==0){
        x=1,y=0;
        return;
    }
    exgcd(b,a%b,y,x);
    y-=a/b*x;
}

int EXGCD(int a,int b,int c){   // ax+by==c 的最小正 x 解
    // cerr<<"a="<<a<<" b="<<b<<" c="<<c<<'\n';
    if(c<0) c+=(-(c/b)+1)*b;
    // cerr<<"a="<<a<<" b="<<b<<" cc="<<c<<'\n';
    int d=__gcd(a,b);
    if(c%d!=0) return inf;
    int x0,y0;
    exgcd(a,b,x0,y0);
    int alf=c/d,bta=(b/d);
    // cerr<<" x00="<<x0<<'\n';
    x0*=alf,y0*=alf;
    // cerr<<" x01="<<x0<<'\n';
    x0=(x0%bta+bta)%bta;
    // cerr<<" x02="<<x0<<'\n';
    return x0;
}

int qpow(int a,int b){
    int ret=1;
    while(b){
        if(b&1) ret*=a;
        a*=a;
        b>>=1;
    }
    return ret;
}

void slv(){
    int a,b,A,B;
    cin>>a>>b;
    A=1,B=b;
    while(B%2==0){
        A*=2;
        B/=2;
    }
    while(B%5==0){
        A*=5;
        B/=5;
    }
    pair<int,int> ans=make_pair(inf,inf);
    for(int x=0;x<=30;x++){
        for(int y=0;y<=10;y++){
            int tmp=qpow(2,x)*qpow(5,y);
            if(tmp*B>1E9) break;
            int C=a*tmp;
            pair<int,int> c=make_pair(EXGCD(A,B,-C),tmp*B);
            if(c.fr<ans.fr) ans=c;
            if(c.fr==ans.fr&&c.sc<ans.sc) ans.sc=c.sc;
        }
    }
    cout<<ans.fr<<' '<<ans.sc<<'\n';
    return;
}

signed main(){
    int T;
    cin>>T;
    while(T--) slv();
}

/*

4
1 2
2 3
3 7
19 79

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3564kb

input:

4
5
1 2
1 5
1 2
1 2
2 2
5
1 1
2 4
2 3
5 5
3 4
5
3 5
1 2
3 4
3 5
3 3
5
1 5
1 4
4 5
5 5
1 2

output:

0 1
0 1
0 1
0 1

result:

wrong answer 4th words differ - expected: '0', found: '1'