QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#509920 | #3799. It's Surely Complex | Tomato_Fish | WA | 1188ms | 126896kb | C++14 | 3.4kb | 2024-08-08 19:49:12 | 2024-08-08 19:49:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long double db;
// db acos(db a) {return acos((long double)a);}
// db cos(db a) {return cos((long double)a);}
// db sin(db a) {return sin((long double)a);}
const db pi=acos((db)-1.);
int fft_n;
const int N=3e6+100;
complex<db> omega[N],omega_inv[N];
void FFT_init(int n){
fft_n=n;
for(int i=0;i<n;i++)
omega[i]=complex<db>(cos(2*pi/n*i),sin(2*pi/n*i));
omega_inv[0]=omega[0];
for(int i=1;i<n;i++) omega_inv[i]=omega[n-i];
}
void FFT(complex<db> *a,int n,int tp){
for(int i=1,j=0;i<n-1;i++){
int k=n;
do
{
j ^= (k>>=1);
} while (j<k);
if(i<j) swap(a[i],a[j]);
}
for(int k=2,m=fft_n/2;k<=n;k*=2,m/=2)
for(int i=0;i<n;i+=k)
for(int j=0;j<k/2;j++){
auto u=a[i+j],v=(tp>0?omega:omega_inv)[m*j]*a[i+j+k/2];
a[i+j]=u+v;
a[i+j+k/2]=u-v;
}
if(tp<0) for(int i=0;i<n;i++) {a[i]/=n;}
}
typedef long long ll;
int mi(int x,int t,int mod){
int d=1;
while(t){
if(t%2) d=(ll)d*x%mod;
x=(ll)x*x%mod;t/=2;
}
return d;
}
int ni(int x,int mod) {return mi(x,mod-2,mod);}
complex<db> a[N];
int p;ll n;
struct com{
int c1,c2;
com() {}
com(int _c1,int _c2) {c1=_c1;c2=_c2;}
};
com operator + (com n1,com n2) {return com((n1.c1+n2.c1)%p,(n1.c2+n2.c2)%p);}
com operator * (com n1,com n2) {return com(((ll)n1.c1*n2.c1-(ll)n1.c2*n2.c2%p+p)%p,((ll)n1.c2*n2.c1+(ll)n1.c1*n2.c2%p)%p);}
__int128 b[N];
void print(__int128 x){
int sta[110],tot=0;
while(x) sta[++tot]=x%10,x/=10;
if(!tot) printf("0");
else{
while(tot) putchar(sta[tot]+'0'),tot--;
}
}
com Mi(com x,ll t){
com d=com(1,0);
while(t){
if(t%2) d=d*x;
x=x*x;t/=2;
}
return d;
}
int main()
{
scanf("%d%lld",&p,&n);
// if(n>=p&&p%4==1){
// printf("0 0\n");
// return 0;
// }
// n%=p;
int maxn=(1<<20);
for(int i=0;i<p;i++){
int t=(ll)i*i%p;
ll tmp=(n/p)+(i<=n%p);
a[t]=a[t]+complex<db>((db)(tmp%(8*p-8)),0);
}
complex<db> w;
for(int i=0;i<p;i++){
w=w+a[i]*a[p-i];
}
// printf("%.10Lf\n",Summ);
FFT_init(maxn);
FFT(a,maxn,1);
for(int i=0;i<maxn;i++) a[i]=a[i]*a[i];
FFT(a,maxn,-1);
// printf("%.10Lf\n",a[p].real());
__int128 Sum=0;int d=1;
for(int i=0;i<maxn;i++){
b[i]=(__int128)(a[i].real()+0.01);
}
for(int i=1;i<p;i++){
int t=(ll)i*i%p;
b[2*t]=(b[2*t]-((n/p)+(i<=n%p))%(8*p-8)+(8*p-8))%(8*p-8);
}
b[0]=b[0]-(__int128)(n/p+1)*(n/p+1);
// for(int i=0;i<2*p;i++) printf("%lld ",b[i]);printf("\n");
// printf("%lld %lld\n",b[p],b[0]);
for(int i=1;i<maxn;i++){
// if(i%4==3) continue;
// if(i%p==0) continue;
if(i%p==0&&b[i]) d=0;
Sum+=(b[i]/2);
d=(ll)d*mi(i,(b[i]/2)%(p-1),p)%p;
}
com Ans;
if(Sum%4==0) Ans=com(d,0);
else if(Sum%4==1) Ans=com(0,d);
else if(Sum%4==2) Ans=com((p-d)%p,0);
else Ans=com(0,(p-d)%p);
// printf("%d %d\n",Ans.c1,Ans.c2);
for(int i=1;i<p;i++) Ans=Ans*Mi(com(i,i),(n/p)+(i<=n%p));
printf("%d %d\n",Ans.c1,Ans.c2);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 611ms
memory: 124904kb
input:
2 1
output:
1 1
result:
ok single line: '1 1'
Test #2:
score: 0
Accepted
time: 613ms
memory: 124716kb
input:
2 2
output:
1 1
result:
ok single line: '1 1'
Test #3:
score: 0
Accepted
time: 627ms
memory: 124848kb
input:
2 3
output:
0 0
result:
ok single line: '0 0'
Test #4:
score: 0
Accepted
time: 636ms
memory: 126772kb
input:
2 4
output:
0 0
result:
ok single line: '0 0'
Test #5:
score: 0
Accepted
time: 618ms
memory: 124740kb
input:
3 1
output:
2 1
result:
ok single line: '2 1'
Test #6:
score: 0
Accepted
time: 633ms
memory: 126796kb
input:
3 2
output:
2 0
result:
ok single line: '2 0'
Test #7:
score: 0
Accepted
time: 635ms
memory: 124748kb
input:
3 3
output:
1 0
result:
ok single line: '1 0'
Test #8:
score: 0
Accepted
time: 619ms
memory: 124744kb
input:
3 4
output:
1 1
result:
ok single line: '1 1'
Test #9:
score: 0
Accepted
time: 607ms
memory: 126676kb
input:
3 5
output:
1 0
result:
ok single line: '1 0'
Test #10:
score: 0
Accepted
time: 623ms
memory: 124816kb
input:
3 6
output:
1 0
result:
ok single line: '1 0'
Test #11:
score: 0
Accepted
time: 627ms
memory: 124820kb
input:
5 1
output:
4 1
result:
ok single line: '4 1'
Test #12:
score: 0
Accepted
time: 615ms
memory: 124740kb
input:
5 2
output:
0 0
result:
ok single line: '0 0'
Test #13:
score: 0
Accepted
time: 616ms
memory: 124748kb
input:
5 3
output:
0 0
result:
ok single line: '0 0'
Test #14:
score: 0
Accepted
time: 626ms
memory: 124820kb
input:
5 4
output:
0 0
result:
ok single line: '0 0'
Test #15:
score: 0
Accepted
time: 628ms
memory: 126896kb
input:
5 5
output:
0 0
result:
ok single line: '0 0'
Test #16:
score: 0
Accepted
time: 617ms
memory: 124824kb
input:
5 6
output:
0 0
result:
ok single line: '0 0'
Test #17:
score: 0
Accepted
time: 624ms
memory: 124692kb
input:
5 7
output:
0 0
result:
ok single line: '0 0'
Test #18:
score: 0
Accepted
time: 610ms
memory: 124748kb
input:
5 8
output:
0 0
result:
ok single line: '0 0'
Test #19:
score: 0
Accepted
time: 624ms
memory: 124744kb
input:
5 9
output:
0 0
result:
ok single line: '0 0'
Test #20:
score: 0
Accepted
time: 628ms
memory: 124888kb
input:
5 10
output:
0 0
result:
ok single line: '0 0'
Test #21:
score: 0
Accepted
time: 634ms
memory: 124596kb
input:
7 1
output:
6 1
result:
ok single line: '6 1'
Test #22:
score: 0
Accepted
time: 636ms
memory: 124636kb
input:
7 2
output:
3 0
result:
ok single line: '3 0'
Test #23:
score: 0
Accepted
time: 624ms
memory: 124740kb
input:
7 3
output:
2 5
result:
ok single line: '2 5'
Test #24:
score: 0
Accepted
time: 627ms
memory: 124852kb
input:
7 4
output:
1 0
result:
ok single line: '1 0'
Test #25:
score: 0
Accepted
time: 625ms
memory: 124744kb
input:
7 5
output:
5 2
result:
ok single line: '5 2'
Test #26:
score: 0
Accepted
time: 611ms
memory: 124736kb
input:
7 6
output:
6 0
result:
ok single line: '6 0'
Test #27:
score: 0
Accepted
time: 620ms
memory: 124796kb
input:
7 7
output:
1 0
result:
ok single line: '1 0'
Test #28:
score: 0
Accepted
time: 631ms
memory: 124888kb
input:
7 8
output:
4 4
result:
ok single line: '4 4'
Test #29:
score: 0
Accepted
time: 611ms
memory: 124820kb
input:
7 9
output:
4 0
result:
ok single line: '4 0'
Test #30:
score: 0
Accepted
time: 633ms
memory: 124632kb
input:
7 10
output:
2 2
result:
ok single line: '2 2'
Test #31:
score: 0
Accepted
time: 625ms
memory: 124788kb
input:
7 11
output:
1 0
result:
ok single line: '1 0'
Test #32:
score: 0
Accepted
time: 624ms
memory: 124900kb
input:
7 12
output:
4 4
result:
ok single line: '4 4'
Test #33:
score: 0
Accepted
time: 630ms
memory: 124720kb
input:
7 13
output:
1 0
result:
ok single line: '1 0'
Test #34:
score: 0
Accepted
time: 626ms
memory: 124724kb
input:
7 14
output:
1 0
result:
ok single line: '1 0'
Test #35:
score: 0
Accepted
time: 629ms
memory: 124688kb
input:
2 1000000000000000000
output:
0 0
result:
ok single line: '0 0'
Test #36:
score: 0
Accepted
time: 617ms
memory: 124848kb
input:
3 1000000000000000000
output:
1 1
result:
ok single line: '1 1'
Test #37:
score: 0
Accepted
time: 1186ms
memory: 124600kb
input:
499979 1000000000000000000
output:
486292 0
result:
ok single line: '486292 0'
Test #38:
score: 0
Accepted
time: 1188ms
memory: 126652kb
input:
499973 1000000000000000000
output:
0 0
result:
ok single line: '0 0'
Test #39:
score: 0
Accepted
time: 626ms
memory: 124888kb
input:
2 576460752303423488
output:
0 0
result:
ok single line: '0 0'
Test #40:
score: 0
Accepted
time: 636ms
memory: 124884kb
input:
3 864691128455135232
output:
1 0
result:
ok single line: '1 0'
Test #41:
score: 0
Accepted
time: 634ms
memory: 124820kb
input:
43 41
output:
32 11
result:
ok single line: '32 11'
Test #42:
score: 0
Accepted
time: 627ms
memory: 124636kb
input:
89 646243632056227082
output:
0 0
result:
ok single line: '0 0'
Test #43:
score: 0
Accepted
time: 623ms
memory: 124748kb
input:
79 3818048575756175
output:
61 18
result:
ok single line: '61 18'
Test #44:
score: 0
Accepted
time: 613ms
memory: 124736kb
input:
43 417918461
output:
1 0
result:
ok single line: '1 0'
Test #45:
score: 0
Accepted
time: 653ms
memory: 124744kb
input:
67 9225777529942049
output:
26 0
result:
ok single line: '26 0'
Test #46:
score: 0
Accepted
time: 633ms
memory: 124688kb
input:
29 1894616718601
output:
0 0
result:
ok single line: '0 0'
Test #47:
score: 0
Accepted
time: 634ms
memory: 124600kb
input:
73 24891833259
output:
0 0
result:
ok single line: '0 0'
Test #48:
score: 0
Accepted
time: 623ms
memory: 124884kb
input:
751 45
output:
36 715
result:
ok single line: '36 715'
Test #49:
score: 0
Accepted
time: 621ms
memory: 124792kb
input:
631 870852734504724166
output:
101 0
result:
ok single line: '101 0'
Test #50:
score: 0
Accepted
time: 612ms
memory: 124720kb
input:
479 939006
output:
52 0
result:
ok single line: '52 0'
Test #51:
score: 0
Accepted
time: 616ms
memory: 124820kb
input:
503 223239772447
output:
381 0
result:
ok single line: '381 0'
Test #52:
score: 0
Accepted
time: 617ms
memory: 126820kb
input:
317 73782933513241136
output:
0 0
result:
ok single line: '0 0'
Test #53:
score: 0
Accepted
time: 601ms
memory: 124748kb
input:
577 4897864747011
output:
0 0
result:
ok single line: '0 0'
Test #54:
score: 0
Accepted
time: 632ms
memory: 126792kb
input:
571 7326187013
output:
400 171
result:
ok single line: '400 171'
Test #55:
score: 0
Accepted
time: 616ms
memory: 126680kb
input:
9787 39
output:
953 8834
result:
ok single line: '953 8834'
Test #56:
score: 0
Accepted
time: 635ms
memory: 124956kb
input:
4177 296229723194145403
output:
0 0
result:
ok single line: '0 0'
Test #57:
score: 0
Accepted
time: 649ms
memory: 124952kb
input:
5039 71501150263015946
output:
4425 4425
result:
ok single line: '4425 4425'
Test #58:
score: 0
Accepted
time: 619ms
memory: 124692kb
input:
7027 44142
output:
6075 0
result:
ok single line: '6075 0'
Test #59:
score: 0
Accepted
time: 625ms
memory: 124948kb
input:
1877 5605079
output:
0 0
result:
ok single line: '0 0'
Test #60:
score: 0
Accepted
time: 619ms
memory: 124820kb
input:
2251 187
output:
1847 404
result:
ok single line: '1847 404'
Test #61:
score: 0
Accepted
time: 644ms
memory: 124848kb
input:
3863 699
output:
3850 13
result:
ok single line: '3850 13'
Test #62:
score: 0
Accepted
time: 618ms
memory: 124636kb
input:
92557 64
output:
28440 0
result:
ok single line: '28440 0'
Test #63:
score: 0
Accepted
time: 689ms
memory: 124792kb
input:
62047 410196757795686372
output:
11479 11479
result:
ok single line: '11479 11479'
Test #64:
score: 0
Accepted
time: 661ms
memory: 124632kb
input:
67129 2833304630
output:
0 0
result:
ok single line: '0 0'
Test #65:
score: 0
Accepted
time: 695ms
memory: 124796kb
input:
90793 25188225487855
output:
0 0
result:
ok single line: '0 0'
Test #66:
score: 0
Accepted
time: 619ms
memory: 124716kb
input:
55313 111467
output:
0 0
result:
ok single line: '0 0'
Test #67:
score: -100
Wrong Answer
time: 662ms
memory: 124740kb
input:
69151 718198020401
output:
16543 52608
result:
wrong answer 1st lines differ - expected: '9621 59530', found: '16543 52608'