帮忙看看如何优化:
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
l=read();
r=read();
k=read();
for(int i=r;i>=l;i--){
if(i==0){
long long l=1;
mx=maax(l,mx);
continue;
}
long long p = jc(i,k);
p=p%k;
mx=maax(mx,p);
}
printf("%lld\n",mx);
这是核心代码,maax 为自写函数比大小,jc 为阶乘代码,每步都会取余。