QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#216009#3799. It's Surely Complexucup-team004#AC ✓409ms79624kbC++203.1kb2023-10-15 15:07:072023-10-15 15:07:07

Judging History

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

  • [2023-10-15 15:07:07]
  • 评测
  • 测评结果:AC
  • 用时:409ms
  • 内存:79624kb
  • [2023-10-15 15:07:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N=(1<<20)+5;

typedef long long ll;

typedef complex<double> C;
const double PI=acos(-1);


int p;
struct Complex{
    int x,y;
    Complex(int x_=0,int y_=0):x(x_),y(y_){}

    Complex operator + (const Complex&a)const{return Complex((x+a.x)%p,(y+a.y)%p);}
    Complex operator - (const Complex&a)const{return Complex((x-a.x+p)%p,(y-a.y+p)%p);}
    Complex operator * (const Complex&a)const{return Complex(((ll)x*a.x-(ll)y*a.y%p+p)%p,((ll)x*a.y+(ll)y*a.x)%p);}
};

Complex ksm(Complex a,ll b,Complex c=Complex(1,0)){
    for(;b;b/=2,a=a*a)
        if(b&1)c=c*a;
    return c;
}

int rev_[N],n_,lgn_;
C omg_[N],ww_[N];
void FFT_init(int n){
    for(lgn_=0;(1<<lgn_)<=n;++lgn_);n_=1<<lgn_;
    rev_[0]=0;
    for(int i=1;i<n_;++i)
        rev_[i]=(rev_[i>>1]>>1)|((i&1)<<(lgn_-1));
    for(int i=0;i<n_;++i)
        omg_[i]=polar(1.0,2*PI*i/n_);
}

void FFT(C*a,int flag=0){
    for(int i=0;i<n_;++i)
        if(i<rev_[i])
            swap(a[i],a[rev_[i]]);
    for(int i=0;i<lgn_;++i){
        int t=1<<i;
        for(int j=0;j<t;++j)
            ww_[j]=omg_[j<<(lgn_-i-1)];
        for(int j=0;j<n_;j+=t<<1){
            C*f=a+j,*g=a+j+t;
            for(int k=0;k<t;++k){
                C s=g[k]*ww_[k];
                g[k]=f[k]-s;
                f[k]=f[k]+s;
            }
        }
    }
    if(flag){
        reverse(a+1,a+n_);
        for(int i=0;i<n_;++i)
            a[i]/=n_;
    }
}


int find_g(int p){
	if(p==2)return 1;
    for(int i=1;;++i){
        int pw=1;
        for(int j=1;j<p-1;++j){
            pw=(ll)pw*i%p;
            if(pw==1)break;
        }
        if(pw==1)continue;
        return i;
    }
}

ll n;
int id[N],pw[N];
C pf[N],pg[N];
int f[N];


int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>p>>n;
    ll a=n/p,b=n%p;
    int g=find_g(p);
    id[1]=0;
    pw[0]=1;
    for(int i=1;i<p-1;++i){
        pw[i]=(ll)pw[i-1]*g%p;
        id[pw[i]]=i;
    }
    for(int i=1;i<=b;++i)
        pf[id[i]]+=1,pg[p-1-id[i]]+=1;
    FFT_init(2*p);
    FFT(pf);
    
    FFT(pg);
    for(int i=0;i<n_;++i)
        pf[i]*=pg[i];
    FFT(pf,1);
    for(int i=0;i<p-1;++i){
        int s=pf[i].real()+pf[i+p-1].real()+0.5;
        f[pw[i]]=s;
    }

    Complex ans(1,0);
    Complex ans_b(1,0),ans_a(1,0);
    Complex tmp=ksm(Complex(0,1),p);
    for(int i=1;i<p;++i){
        Complex res=ksm(Complex(0,i),p)-Complex(0,i);
        ans_b=ans_b*res;
        ans_b=ans_b*Complex(i,0);
        ans_b=ans_b*Complex(0,i);
        ans_a=ans_a*Complex(i,0);
        ans_a=ans_a*Complex(0,i);
        if(i<=b){
            ans_a=ans_a*res;
            ans=ans*Complex(i,0);
            ans=ans*Complex(0,i);
            ans=ans*ksm(Complex(i,0),b);
        }
        if(i>=p-b)
            ans_a=ans_a*res*tmp;
    }
    ans_a=ksm(ans_a,a);
    ans_b=ksm(ans_b,a);
    ans_b=ksm(ans_b,a);
    for(int i=1;i<p;++i)if(f[i]){
        ans=ans*ksm(Complex(1,i),f[i]);
    }
    ans=ans*ans_a*ans_b;
    cout<<ans.x<<' '<<ans.y<<'\n';
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 14160kb

input:

2 1

output:

1 1

result:

ok single line: '1 1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 14104kb

input:

2 2

output:

1 1

result:

ok single line: '1 1'

Test #3:

score: 0
Accepted
time: 2ms
memory: 14228kb

input:

2 3

output:

0 0

result:

ok single line: '0 0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 14132kb

input:

2 4

output:

0 0

result:

ok single line: '0 0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 14104kb

input:

3 1

output:

2 1

result:

ok single line: '2 1'

Test #6:

score: 0
Accepted
time: 2ms
memory: 14112kb

input:

3 2

output:

2 0

result:

ok single line: '2 0'

Test #7:

score: 0
Accepted
time: 0ms
memory: 14132kb

input:

3 3

output:

1 0

result:

ok single line: '1 0'

Test #8:

score: 0
Accepted
time: 2ms
memory: 14128kb

input:

3 4

output:

1 1

result:

ok single line: '1 1'

Test #9:

score: 0
Accepted
time: 2ms
memory: 14128kb

input:

3 5

output:

1 0

result:

ok single line: '1 0'

Test #10:

score: 0
Accepted
time: 0ms
memory: 14228kb

input:

3 6

output:

1 0

result:

ok single line: '1 0'

Test #11:

score: 0
Accepted
time: 2ms
memory: 14260kb

input:

5 1

output:

4 1

result:

ok single line: '4 1'

Test #12:

score: 0
Accepted
time: 1ms
memory: 14132kb

input:

5 2

output:

0 0

result:

ok single line: '0 0'

Test #13:

score: 0
Accepted
time: 2ms
memory: 14148kb

input:

5 3

output:

0 0

result:

ok single line: '0 0'

Test #14:

score: 0
Accepted
time: 2ms
memory: 14032kb

input:

5 4

output:

0 0

result:

ok single line: '0 0'

Test #15:

score: 0
Accepted
time: 0ms
memory: 14160kb

input:

5 5

output:

0 0

result:

ok single line: '0 0'

Test #16:

score: 0
Accepted
time: 0ms
memory: 14044kb

input:

5 6

output:

0 0

result:

ok single line: '0 0'

Test #17:

score: 0
Accepted
time: 0ms
memory: 14164kb

input:

5 7

output:

0 0

result:

ok single line: '0 0'

Test #18:

score: 0
Accepted
time: 2ms
memory: 14164kb

input:

5 8

output:

0 0

result:

ok single line: '0 0'

Test #19:

score: 0
Accepted
time: 2ms
memory: 14052kb

input:

5 9

output:

0 0

result:

ok single line: '0 0'

Test #20:

score: 0
Accepted
time: 0ms
memory: 14164kb

input:

5 10

output:

0 0

result:

ok single line: '0 0'

Test #21:

score: 0
Accepted
time: 0ms
memory: 14156kb

input:

7 1

output:

6 1

result:

ok single line: '6 1'

Test #22:

score: 0
Accepted
time: 1ms
memory: 14160kb

input:

7 2

output:

3 0

result:

ok single line: '3 0'

Test #23:

score: 0
Accepted
time: 2ms
memory: 14104kb

input:

7 3

output:

2 5

result:

ok single line: '2 5'

Test #24:

score: 0
Accepted
time: 0ms
memory: 14028kb

input:

7 4

output:

1 0

result:

ok single line: '1 0'

Test #25:

score: 0
Accepted
time: 2ms
memory: 14036kb

input:

7 5

output:

5 2

result:

ok single line: '5 2'

Test #26:

score: 0
Accepted
time: 0ms
memory: 14160kb

input:

7 6

output:

6 0

result:

ok single line: '6 0'

Test #27:

score: 0
Accepted
time: 1ms
memory: 14228kb

input:

7 7

output:

1 0

result:

ok single line: '1 0'

Test #28:

score: 0
Accepted
time: 1ms
memory: 14160kb

input:

7 8

output:

4 4

result:

ok single line: '4 4'

Test #29:

score: 0
Accepted
time: 0ms
memory: 14268kb

input:

7 9

output:

4 0

result:

ok single line: '4 0'

Test #30:

score: 0
Accepted
time: 2ms
memory: 14152kb

input:

7 10

output:

2 2

result:

ok single line: '2 2'

Test #31:

score: 0
Accepted
time: 2ms
memory: 14108kb

input:

7 11

output:

1 0

result:

ok single line: '1 0'

Test #32:

score: 0
Accepted
time: 0ms
memory: 14148kb

input:

7 12

output:

4 4

result:

ok single line: '4 4'

Test #33:

score: 0
Accepted
time: 0ms
memory: 14100kb

input:

7 13

output:

1 0

result:

ok single line: '1 0'

Test #34:

score: 0
Accepted
time: 2ms
memory: 14040kb

input:

7 14

output:

1 0

result:

ok single line: '1 0'

Test #35:

score: 0
Accepted
time: 0ms
memory: 14160kb

input:

2 1000000000000000000

output:

0 0

result:

ok single line: '0 0'

Test #36:

score: 0
Accepted
time: 2ms
memory: 14104kb

input:

3 1000000000000000000

output:

1 1

result:

ok single line: '1 1'

Test #37:

score: 0
Accepted
time: 399ms
memory: 79344kb

input:

499979 1000000000000000000

output:

486292 0

result:

ok single line: '486292 0'

Test #38:

score: 0
Accepted
time: 409ms
memory: 79016kb

input:

499973 1000000000000000000

output:

0 0

result:

ok single line: '0 0'

Test #39:

score: 0
Accepted
time: 2ms
memory: 14036kb

input:

2 576460752303423488

output:

0 0

result:

ok single line: '0 0'

Test #40:

score: 0
Accepted
time: 2ms
memory: 14036kb

input:

3 864691128455135232

output:

1 0

result:

ok single line: '1 0'

Test #41:

score: 0
Accepted
time: 0ms
memory: 14124kb

input:

43 41

output:

32 11

result:

ok single line: '32 11'

Test #42:

score: 0
Accepted
time: 2ms
memory: 14140kb

input:

89 646243632056227082

output:

0 0

result:

ok single line: '0 0'

Test #43:

score: 0
Accepted
time: 0ms
memory: 14168kb

input:

79 3818048575756175

output:

61 18

result:

ok single line: '61 18'

Test #44:

score: 0
Accepted
time: 0ms
memory: 14132kb

input:

43 417918461

output:

1 0

result:

ok single line: '1 0'

Test #45:

score: 0
Accepted
time: 0ms
memory: 14236kb

input:

67 9225777529942049

output:

26 0

result:

ok single line: '26 0'

Test #46:

score: 0
Accepted
time: 0ms
memory: 14056kb

input:

29 1894616718601

output:

0 0

result:

ok single line: '0 0'

Test #47:

score: 0
Accepted
time: 2ms
memory: 14184kb

input:

73 24891833259

output:

0 0

result:

ok single line: '0 0'

Test #48:

score: 0
Accepted
time: 2ms
memory: 14192kb

input:

751 45

output:

36 715

result:

ok single line: '36 715'

Test #49:

score: 0
Accepted
time: 0ms
memory: 14192kb

input:

631 870852734504724166

output:

101 0

result:

ok single line: '101 0'

Test #50:

score: 0
Accepted
time: 0ms
memory: 14060kb

input:

479 939006

output:

52 0

result:

ok single line: '52 0'

Test #51:

score: 0
Accepted
time: 0ms
memory: 14092kb

input:

503 223239772447

output:

381 0

result:

ok single line: '381 0'

Test #52:

score: 0
Accepted
time: 0ms
memory: 14192kb

input:

317 73782933513241136

output:

0 0

result:

ok single line: '0 0'

Test #53:

score: 0
Accepted
time: 2ms
memory: 14332kb

input:

577 4897864747011

output:

0 0

result:

ok single line: '0 0'

Test #54:

score: 0
Accepted
time: 2ms
memory: 14196kb

input:

571 7326187013

output:

400 171

result:

ok single line: '400 171'

Test #55:

score: 0
Accepted
time: 4ms
memory: 21368kb

input:

9787 39

output:

953 8834

result:

ok single line: '953 8834'

Test #56:

score: 0
Accepted
time: 3ms
memory: 14636kb

input:

4177 296229723194145403

output:

0 0

result:

ok single line: '0 0'

Test #57:

score: 0
Accepted
time: 6ms
memory: 14576kb

input:

5039 71501150263015946

output:

4425 4425

result:

ok single line: '4425 4425'

Test #58:

score: 0
Accepted
time: 4ms
memory: 20744kb

input:

7027 44142

output:

6075 0

result:

ok single line: '6075 0'

Test #59:

score: 0
Accepted
time: 3ms
memory: 14244kb

input:

1877 5605079

output:

0 0

result:

ok single line: '0 0'

Test #60:

score: 0
Accepted
time: 0ms
memory: 14324kb

input:

2251 187

output:

1847 404

result:

ok single line: '1847 404'

Test #61:

score: 0
Accepted
time: 0ms
memory: 14436kb

input:

3863 699

output:

3850 13

result:

ok single line: '3850 13'

Test #62:

score: 0
Accepted
time: 50ms
memory: 28856kb

input:

92557 64

output:

28440 0

result:

ok single line: '28440 0'

Test #63:

score: 0
Accepted
time: 45ms
memory: 20540kb

input:

62047 410196757795686372

output:

11479 11479

result:

ok single line: '11479 11479'

Test #64:

score: 0
Accepted
time: 72ms
memory: 36824kb

input:

67129 2833304630

output:

0 0

result:

ok single line: '0 0'

Test #65:

score: 0
Accepted
time: 84ms
memory: 28952kb

input:

90793 25188225487855

output:

0 0

result:

ok single line: '0 0'

Test #66:

score: 0
Accepted
time: 27ms
memory: 20492kb

input:

55313 111467

output:

0 0

result:

ok single line: '0 0'

Test #67:

score: 0
Accepted
time: 69ms
memory: 30784kb

input:

69151 718198020401

output:

9621 59530

result:

ok single line: '9621 59530'

Test #68:

score: 0
Accepted
time: 41ms
memory: 22512kb

input:

48571 56301

output:

2628 0

result:

ok single line: '2628 0'

Test #69:

score: 0
Accepted
time: 217ms
memory: 77716kb

input:

326983 51

output:

39793 287190

result:

ok single line: '39793 287190'

Test #70:

score: 0
Accepted
time: 400ms
memory: 79624kb

input:

406183 933021611983655873

output:

238788 167395

result:

ok single line: '238788 167395'

Test #71:

score: 0
Accepted
time: 152ms
memory: 45424kb

input:

152729 7971425537345

output:

0 0

result:

ok single line: '0 0'

Test #72:

score: 0
Accepted
time: 139ms
memory: 51708kb

input:

183047 6977

output:

141264 41783

result:

ok single line: '141264 41783'

Test #73:

score: 0
Accepted
time: 140ms
memory: 45796kb

input:

207973 3240

output:

0 0

result:

ok single line: '0 0'

Test #74:

score: 0
Accepted
time: 122ms
memory: 45332kb

input:

141907 10497585978

output:

141777 141777

result:

ok single line: '141777 141777'

Test #75:

score: 0
Accepted
time: 234ms
memory: 78032kb

input:

279317 6562

output:

0 0

result:

ok single line: '0 0'