易得 ans=(anX0+(i=0∑n−1ai)c)modmmodg
具体代码如下:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int m,a,c,x0,n,g;
int pro(int a,int b){
int s=0;
while(b){
if(b&1LL) s=(s+a)%m;
a=(a+a)%m;
b>>=1LL;
}
return s;
}
int qpow(int a,int b){
int s=1LL;
while(b){
if(b&1LL) s=pro(s,a);
a=pro(a,a);
b>>=1LL;
}
return s;
}
int sum(int a,int b){
if(b==1) return a;
int t=sum(a,b>>1LL),s=pro(t,qpow(a,b>>1LL)+1);
if(b&1) return (s+qpow(a,b))%m;
else return s;
}
signed main(){
scanf("%lld%lld%lld%lld%lld%lld",&m,&a,&c,&x0,&n,&g);
printf("%lld",pro(qpow(a,n)+pro(sum(a,n-1)+1,c))%m%g);
return 0;
}
(留了一个坑,这样应该不算tlqtj吧)如果是的话,@我,紫衫。