QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#509951 | #3799. It's Surely Complex | Tomato_Fish | WA | 651ms | 126888kb | C++14 | 3.3kb | 2024-08-08 20:06:52 | 2024-08-08 20:06:54 |
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);
}
// 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: 636ms
memory: 124716kb
input:
2 1
output:
1 1
result:
ok single line: '1 1'
Test #2:
score: 0
Accepted
time: 621ms
memory: 124688kb
input:
2 2
output:
1 1
result:
ok single line: '1 1'
Test #3:
score: 0
Accepted
time: 612ms
memory: 124716kb
input:
2 3
output:
0 0
result:
ok single line: '0 0'
Test #4:
score: 0
Accepted
time: 651ms
memory: 124888kb
input:
2 4
output:
0 0
result:
ok single line: '0 0'
Test #5:
score: 0
Accepted
time: 631ms
memory: 124692kb
input:
3 1
output:
2 1
result:
ok single line: '2 1'
Test #6:
score: 0
Accepted
time: 636ms
memory: 126888kb
input:
3 2
output:
2 0
result:
ok single line: '2 0'
Test #7:
score: 0
Accepted
time: 626ms
memory: 124900kb
input:
3 3
output:
1 0
result:
ok single line: '1 0'
Test #8:
score: 0
Accepted
time: 638ms
memory: 124740kb
input:
3 4
output:
1 1
result:
ok single line: '1 1'
Test #9:
score: 0
Accepted
time: 639ms
memory: 124684kb
input:
3 5
output:
1 0
result:
ok single line: '1 0'
Test #10:
score: 0
Accepted
time: 630ms
memory: 124596kb
input:
3 6
output:
1 0
result:
ok single line: '1 0'
Test #11:
score: 0
Accepted
time: 626ms
memory: 124896kb
input:
5 1
output:
4 1
result:
ok single line: '4 1'
Test #12:
score: 0
Accepted
time: 617ms
memory: 124596kb
input:
5 2
output:
0 0
result:
ok single line: '0 0'
Test #13:
score: 0
Accepted
time: 630ms
memory: 124812kb
input:
5 3
output:
0 0
result:
ok single line: '0 0'
Test #14:
score: 0
Accepted
time: 644ms
memory: 124948kb
input:
5 4
output:
0 0
result:
ok single line: '0 0'
Test #15:
score: 0
Accepted
time: 638ms
memory: 124744kb
input:
5 5
output:
0 0
result:
ok single line: '0 0'
Test #16:
score: 0
Accepted
time: 629ms
memory: 124736kb
input:
5 6
output:
0 0
result:
ok single line: '0 0'
Test #17:
score: 0
Accepted
time: 646ms
memory: 126788kb
input:
5 7
output:
0 0
result:
ok single line: '0 0'
Test #18:
score: 0
Accepted
time: 637ms
memory: 124780kb
input:
5 8
output:
0 0
result:
ok single line: '0 0'
Test #19:
score: -100
Wrong Answer
time: 633ms
memory: 124876kb
input:
5 9
output:
1 0
result:
wrong answer 1st lines differ - expected: '0 0', found: '1 0'