QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#509974 | #3799. It's Surely Complex | Tomato_Fish | AC ✓ | 1187ms | 126796kb | C++14 | 3.6kb | 2024-08-08 20:16:27 | 2024-08-08 20:16:30 |
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);
}
__int128 Summ=0;
for(int i=1;i<p;i++)
Summ=Summ+(__int128)(a[i].real()+0.5)*(__int128)(a[p-i].real()+0.5);
for(int i=1;i<p;i++){
int t=(ll)i*i%p;
if(t*2==p) Summ=Summ-((n/p)+(i<=n%p));
}
if(Summ){
printf("0 0\n");
return 0;
}
// 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.5))%(8*p-8);
}
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);
// 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: 615ms
memory: 124852kb
input:
2 1
output:
1 1
result:
ok single line: '1 1'
Test #2:
score: 0
Accepted
time: 635ms
memory: 124852kb
input:
2 2
output:
1 1
result:
ok single line: '1 1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5664kb
input:
2 3
output:
0 0
result:
ok single line: '0 0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 6032kb
input:
2 4
output:
0 0
result:
ok single line: '0 0'
Test #5:
score: 0
Accepted
time: 624ms
memory: 124892kb
input:
3 1
output:
2 1
result:
ok single line: '2 1'
Test #6:
score: 0
Accepted
time: 617ms
memory: 124808kb
input:
3 2
output:
2 0
result:
ok single line: '2 0'
Test #7:
score: 0
Accepted
time: 630ms
memory: 124744kb
input:
3 3
output:
1 0
result:
ok single line: '1 0'
Test #8:
score: 0
Accepted
time: 630ms
memory: 124792kb
input:
3 4
output:
1 1
result:
ok single line: '1 1'
Test #9:
score: 0
Accepted
time: 638ms
memory: 124704kb
input:
3 5
output:
1 0
result:
ok single line: '1 0'
Test #10:
score: 0
Accepted
time: 644ms
memory: 124904kb
input:
3 6
output:
1 0
result:
ok single line: '1 0'
Test #11:
score: 0
Accepted
time: 619ms
memory: 124640kb
input:
5 1
output:
4 1
result:
ok single line: '4 1'
Test #12:
score: 0
Accepted
time: 1ms
memory: 5780kb
input:
5 2
output:
0 0
result:
ok single line: '0 0'
Test #13:
score: 0
Accepted
time: 1ms
memory: 5852kb
input:
5 3
output:
0 0
result:
ok single line: '0 0'
Test #14:
score: 0
Accepted
time: 1ms
memory: 5748kb
input:
5 4
output:
0 0
result:
ok single line: '0 0'
Test #15:
score: 0
Accepted
time: 1ms
memory: 5780kb
input:
5 5
output:
0 0
result:
ok single line: '0 0'
Test #16:
score: 0
Accepted
time: 1ms
memory: 5892kb
input:
5 6
output:
0 0
result:
ok single line: '0 0'
Test #17:
score: 0
Accepted
time: 1ms
memory: 5784kb
input:
5 7
output:
0 0
result:
ok single line: '0 0'
Test #18:
score: 0
Accepted
time: 1ms
memory: 5776kb
input:
5 8
output:
0 0
result:
ok single line: '0 0'
Test #19:
score: 0
Accepted
time: 1ms
memory: 5668kb
input:
5 9
output:
0 0
result:
ok single line: '0 0'
Test #20:
score: 0
Accepted
time: 1ms
memory: 5892kb
input:
5 10
output:
0 0
result:
ok single line: '0 0'
Test #21:
score: 0
Accepted
time: 631ms
memory: 124608kb
input:
7 1
output:
6 1
result:
ok single line: '6 1'
Test #22:
score: 0
Accepted
time: 620ms
memory: 124720kb
input:
7 2
output:
3 0
result:
ok single line: '3 0'
Test #23:
score: 0
Accepted
time: 653ms
memory: 124724kb
input:
7 3
output:
2 5
result:
ok single line: '2 5'
Test #24:
score: 0
Accepted
time: 629ms
memory: 124900kb
input:
7 4
output:
1 0
result:
ok single line: '1 0'
Test #25:
score: 0
Accepted
time: 642ms
memory: 124744kb
input:
7 5
output:
5 2
result:
ok single line: '5 2'
Test #26:
score: 0
Accepted
time: 634ms
memory: 126740kb
input:
7 6
output:
6 0
result:
ok single line: '6 0'
Test #27:
score: 0
Accepted
time: 644ms
memory: 124824kb
input:
7 7
output:
1 0
result:
ok single line: '1 0'
Test #28:
score: 0
Accepted
time: 621ms
memory: 126652kb
input:
7 8
output:
4 4
result:
ok single line: '4 4'
Test #29:
score: 0
Accepted
time: 650ms
memory: 124800kb
input:
7 9
output:
4 0
result:
ok single line: '4 0'
Test #30:
score: 0
Accepted
time: 631ms
memory: 124696kb
input:
7 10
output:
2 2
result:
ok single line: '2 2'
Test #31:
score: 0
Accepted
time: 631ms
memory: 124692kb
input:
7 11
output:
1 0
result:
ok single line: '1 0'
Test #32:
score: 0
Accepted
time: 639ms
memory: 124744kb
input:
7 12
output:
4 4
result:
ok single line: '4 4'
Test #33:
score: 0
Accepted
time: 625ms
memory: 124748kb
input:
7 13
output:
1 0
result:
ok single line: '1 0'
Test #34:
score: 0
Accepted
time: 633ms
memory: 124844kb
input:
7 14
output:
1 0
result:
ok single line: '1 0'
Test #35:
score: 0
Accepted
time: 1ms
memory: 5784kb
input:
2 1000000000000000000
output:
0 0
result:
ok single line: '0 0'
Test #36:
score: 0
Accepted
time: 629ms
memory: 126776kb
input:
3 1000000000000000000
output:
1 1
result:
ok single line: '1 1'
Test #37:
score: 0
Accepted
time: 1187ms
memory: 124640kb
input:
499979 1000000000000000000
output:
486292 0
result:
ok single line: '486292 0'
Test #38:
score: 0
Accepted
time: 27ms
memory: 20756kb
input:
499973 1000000000000000000
output:
0 0
result:
ok single line: '0 0'
Test #39:
score: 0
Accepted
time: 0ms
memory: 5984kb
input:
2 576460752303423488
output:
0 0
result:
ok single line: '0 0'
Test #40:
score: 0
Accepted
time: 621ms
memory: 124600kb
input:
3 864691128455135232
output:
1 0
result:
ok single line: '1 0'
Test #41:
score: 0
Accepted
time: 629ms
memory: 124772kb
input:
43 41
output:
32 11
result:
ok single line: '32 11'
Test #42:
score: 0
Accepted
time: 1ms
memory: 5892kb
input:
89 646243632056227082
output:
0 0
result:
ok single line: '0 0'
Test #43:
score: 0
Accepted
time: 624ms
memory: 126796kb
input:
79 3818048575756175
output:
61 18
result:
ok single line: '61 18'
Test #44:
score: 0
Accepted
time: 629ms
memory: 124728kb
input:
43 417918461
output:
1 0
result:
ok single line: '1 0'
Test #45:
score: 0
Accepted
time: 643ms
memory: 124720kb
input:
67 9225777529942049
output:
26 0
result:
ok single line: '26 0'
Test #46:
score: 0
Accepted
time: 1ms
memory: 5696kb
input:
29 1894616718601
output:
0 0
result:
ok single line: '0 0'
Test #47:
score: 0
Accepted
time: 1ms
memory: 5836kb
input:
73 24891833259
output:
0 0
result:
ok single line: '0 0'
Test #48:
score: 0
Accepted
time: 636ms
memory: 126792kb
input:
751 45
output:
36 715
result:
ok single line: '36 715'
Test #49:
score: 0
Accepted
time: 645ms
memory: 124848kb
input:
631 870852734504724166
output:
101 0
result:
ok single line: '101 0'
Test #50:
score: 0
Accepted
time: 614ms
memory: 124884kb
input:
479 939006
output:
52 0
result:
ok single line: '52 0'
Test #51:
score: 0
Accepted
time: 636ms
memory: 124604kb
input:
503 223239772447
output:
381 0
result:
ok single line: '381 0'
Test #52:
score: 0
Accepted
time: 1ms
memory: 5780kb
input:
317 73782933513241136
output:
0 0
result:
ok single line: '0 0'
Test #53:
score: 0
Accepted
time: 1ms
memory: 5780kb
input:
577 4897864747011
output:
0 0
result:
ok single line: '0 0'
Test #54:
score: 0
Accepted
time: 621ms
memory: 124904kb
input:
571 7326187013
output:
400 171
result:
ok single line: '400 171'
Test #55:
score: 0
Accepted
time: 625ms
memory: 124964kb
input:
9787 39
output:
953 8834
result:
ok single line: '953 8834'
Test #56:
score: 0
Accepted
time: 1ms
memory: 5984kb
input:
4177 296229723194145403
output:
0 0
result:
ok single line: '0 0'
Test #57:
score: 0
Accepted
time: 640ms
memory: 124952kb
input:
5039 71501150263015946
output:
4425 4425
result:
ok single line: '4425 4425'
Test #58:
score: 0
Accepted
time: 625ms
memory: 124748kb
input:
7027 44142
output:
6075 0
result:
ok single line: '6075 0'
Test #59:
score: 0
Accepted
time: 0ms
memory: 6028kb
input:
1877 5605079
output:
0 0
result:
ok single line: '0 0'
Test #60:
score: 0
Accepted
time: 626ms
memory: 124636kb
input:
2251 187
output:
1847 404
result:
ok single line: '1847 404'
Test #61:
score: 0
Accepted
time: 638ms
memory: 124728kb
input:
3863 699
output:
3850 13
result:
ok single line: '3850 13'
Test #62:
score: 0
Accepted
time: 637ms
memory: 124632kb
input:
92557 64
output:
28440 0
result:
ok single line: '28440 0'
Test #63:
score: 0
Accepted
time: 698ms
memory: 124744kb
input:
62047 410196757795686372
output:
11479 11479
result:
ok single line: '11479 11479'
Test #64:
score: 0
Accepted
time: 0ms
memory: 6884kb
input:
67129 2833304630
output:
0 0
result:
ok single line: '0 0'
Test #65:
score: 0
Accepted
time: 3ms
memory: 8092kb
input:
90793 25188225487855
output:
0 0
result:
ok single line: '0 0'
Test #66:
score: 0
Accepted
time: 3ms
memory: 6168kb
input:
55313 111467
output:
0 0
result:
ok single line: '0 0'
Test #67:
score: 0
Accepted
time: 688ms
memory: 124748kb
input:
69151 718198020401
output:
9621 59530
result:
ok single line: '9621 59530'
Test #68:
score: 0
Accepted
time: 648ms
memory: 124748kb
input:
48571 56301
output:
2628 0
result:
ok single line: '2628 0'
Test #69:
score: 0
Accepted
time: 649ms
memory: 126772kb
input:
326983 51
output:
39793 287190
result:
ok single line: '39793 287190'
Test #70:
score: 0
Accepted
time: 1089ms
memory: 124720kb
input:
406183 933021611983655873
output:
238788 167395
result:
ok single line: '238788 167395'
Test #71:
score: 0
Accepted
time: 6ms
memory: 9528kb
input:
152729 7971425537345
output:
0 0
result:
ok single line: '0 0'
Test #72:
score: 0
Accepted
time: 653ms
memory: 124744kb
input:
183047 6977
output:
141264 41783
result:
ok single line: '141264 41783'
Test #73:
score: 0
Accepted
time: 8ms
memory: 11468kb
input:
207973 3240
output:
0 0
result:
ok single line: '0 0'
Test #74:
score: 0
Accepted
time: 699ms
memory: 124804kb
input:
141907 10497585978
output:
141777 141777
result:
ok single line: '141777 141777'
Test #75:
score: 0
Accepted
time: 13ms
memory: 13436kb
input:
279317 6562
output:
0 0
result:
ok single line: '0 0'