QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#71724 | #4056. 进制转换 | feecle6418 | 100 ✓ | 1035ms | 208524kb | C++14 | 2.2kb | 2023-01-11 21:43:32 | 2023-01-11 21:43:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
const int mod=998244353,N=2097152,g=3,invg=(mod+1)/g;
ll n,pw3[40]={1};
int X,Y,Z,pwY[105]={1},pwZ[105]={1},cnt3[50000005],ans=0;
int tr[2100005],wk[2100005],a[2100005],b[2100005],c[2100005];
int Power(int x,ll y){
int r=1;
while(y){
if(y&1)r=1ll*r*x%mod;
x=1ll*x*x%mod,y>>=1;
}
return r;
}
void GetTr(int l){
for(int i=0;i<l;i++)tr[i]=((tr[i>>1]>>1)|((i&1)?(l>>1):0));
}
void NTT(int a[],int n,int fl){
for(int i=0;i<n;i++)if(i<tr[i])swap(a[i],a[tr[i]]);
for(int i=1;i<n;i<<=1){
int w=Power(fl==1?g:invg,(mod-1)/(i<<1));
wk[0]=1;
for(int j=1;j<i;j++)wk[j]=1ll*wk[j-1]*w%mod;
for(int j=0;j<n;j+=(i<<1)){
int *p=a+j,*q=a+i+j,*t=wk;
for(int k=0;k<i;k++,++p,++q,++t){
int x=*p,y=1ll*(*q)*(*t)%mod,z=x;
x+=y,((x>=mod)&&(x-=mod)),*p=x;
x=z-y,((x<0)&&(x+=mod)),*q=x;
}
}
}
if(fl==-1){
int inv=Power(n,mod-2);
for(int i=0;i<n;i++)a[i]=1ll*a[i]*inv%mod;
}
}
void upd(int &x,int y){
x=(x+y)%mod;
}
int main(){
cin>>n>>X>>Y>>Z;
for(int i=1;i<=100;i++)pwY[i]=1ll*pwY[i-1]*Y%mod,pwZ[i]=1ll*pwZ[i-1]*Z%mod;
for(int i=1;i<=30;i++)pw3[i]=3*pw3[i-1];
for(int i=0;i<pw3[16];i++)cnt3[i]=cnt3[i/3]+(i%3);
int pwX12=Power(X,pw3[12]);
for(int i=0,t=1;i<pw3[16];i++,t=1ll*t*pwX12%mod){
if(i*pw3[12]>n)break;
if((i+1)*pw3[12]-1>n){
for(int j=0;j<pw3[12];j++){
ll x=i*pw3[12]+j;
if(x>n)break;
upd(ans,1ll*pwZ[cnt3[i]+cnt3[j]]*pwY[__builtin_popcountll(x)]%mod*Power(X,x)%mod);
}
continue;
}
ll x=i*pw3[12];
//不进位
upd(a[x&((N-1)>>1)],1ll*pwZ[cnt3[i]]*pwY[__builtin_popcountll(x>>20)]%mod*t%mod);
//进位
upd(b[x&((N-1)>>1)],1ll*pwZ[cnt3[i]]*pwY[__builtin_popcountll((x>>20)+1)]%mod*t%mod);
}
for(int i=0,t=1;i<pw3[12];i++,t=1ll*t*X%mod)upd(c[i],1ll*pwZ[cnt3[i]]*t%mod);
GetTr(N),NTT(a,N,1),NTT(b,N,1),NTT(c,N,1);
for(int i=0;i<N;i++)a[i]=1ll*a[i]*c[i]%mod,b[i]=1ll*b[i]*c[i]%mod;
NTT(a,N,-1),NTT(b,N,-1);
for(int i=0;i<N/2;i++){
upd(ans,1ll*a[i]*pwY[__builtin_popcountll(i)]%mod);
upd(ans,1ll*b[i+N/2]*pwY[__builtin_popcountll(i)]%mod);
}
cout<<(ans-1+mod)%mod;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 416ms
memory: 208356kb
input:
9134097 778012792 263448561 839843856
output:
887680205
result:
ok 1 number(s): "887680205"
Test #2:
score: 5
Accepted
time: 462ms
memory: 208428kb
input:
9896386 2948513 263418583 271155379
output:
853292631
result:
ok 1 number(s): "853292631"
Test #3:
score: 5
Accepted
time: 431ms
memory: 208396kb
input:
9150910 827328107 842171962 39947937
output:
534921610
result:
ok 1 number(s): "534921610"
Test #4:
score: 5
Accepted
time: 973ms
memory: 208356kb
input:
9586674634211 1 1 58301262
output:
13306748
result:
ok 1 number(s): "13306748"
Test #5:
score: 5
Accepted
time: 961ms
memory: 208524kb
input:
9774917720998 1 1 609549524
output:
825025220
result:
ok 1 number(s): "825025220"
Test #6:
score: 5
Accepted
time: 961ms
memory: 208408kb
input:
9765239207265 422503033 1 719749187
output:
993518920
result:
ok 1 number(s): "993518920"
Test #7:
score: 5
Accepted
time: 1023ms
memory: 208396kb
input:
9732354736444 277693641 1 501293609
output:
77844778
result:
ok 1 number(s): "77844778"
Test #8:
score: 5
Accepted
time: 456ms
memory: 208496kb
input:
9004409828 377918953 449219487 26422407
output:
110868569
result:
ok 1 number(s): "110868569"
Test #9:
score: 5
Accepted
time: 436ms
memory: 208400kb
input:
9579878149 820453354 218842704 133154415
output:
727248713
result:
ok 1 number(s): "727248713"
Test #10:
score: 5
Accepted
time: 462ms
memory: 208416kb
input:
9475807443 305433821 391589421 170059051
output:
372839725
result:
ok 1 number(s): "372839725"
Test #11:
score: 5
Accepted
time: 484ms
memory: 208416kb
input:
484758270277 372146623 410538257 35340632
output:
575284574
result:
ok 1 number(s): "575284574"
Test #12:
score: 5
Accepted
time: 469ms
memory: 208392kb
input:
473458173541 864158404 220259603 529747800
output:
610487662
result:
ok 1 number(s): "610487662"
Test #13:
score: 5
Accepted
time: 544ms
memory: 208412kb
input:
459992983903 359742981 983942229 552405867
output:
81366483
result:
ok 1 number(s): "81366483"
Test #14:
score: 5
Accepted
time: 533ms
memory: 208404kb
input:
462331701308 665849375 563297194 141092054
output:
774987426
result:
ok 1 number(s): "774987426"
Test #15:
score: 5
Accepted
time: 897ms
memory: 208412kb
input:
9061635042931 746632077 302662913 559990819
output:
274721229
result:
ok 1 number(s): "274721229"
Test #16:
score: 5
Accepted
time: 1035ms
memory: 208416kb
input:
9653325901537 559549569 638292572 474780356
output:
418906016
result:
ok 1 number(s): "418906016"
Test #17:
score: 5
Accepted
time: 944ms
memory: 208484kb
input:
9640271229478 619740479 644097590 907038757
output:
936646026
result:
ok 1 number(s): "936646026"
Test #18:
score: 5
Accepted
time: 957ms
memory: 208424kb
input:
9781711161203 988850684 154464719 995932763
output:
166841144
result:
ok 1 number(s): "166841144"
Test #19:
score: 5
Accepted
time: 1003ms
memory: 208412kb
input:
9156325004698 915375188 316066096 217969045
output:
306877956
result:
ok 1 number(s): "306877956"
Test #20:
score: 5
Accepted
time: 944ms
memory: 208484kb
input:
9042535293051 906265264 156788435 622201740
output:
397975092
result:
ok 1 number(s): "397975092"