题目
题解
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,m,p;
ll pw(ll x,ll y){
ll z=1;
for (;y;y>>=1,x=x*x%p)
if (y&1) z=z*x%p;
return z;
}
int main(){
scanf("%lld%lld%lld%lld",&n,&k,&m,&p);n%=p;
printf("%lld",(pw(m,k-1)*n%p-(k-1)*pw(m,k-2)%p*(m*(m+1)/2%p)%p+p)%p);
}