P4925
明明乘之前也模了,为什么爆ull
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll unsigned long long
using namespace std;
ll k,l,p,s,w;
ll ksm(ll a,ll b,ll p){
ll ans=1;
a%=p;
while(b){
if(b&1)ans=ans%p*a%p;
a=a%p*a%p;
b>>=1;
}
return ans;
}
int main(){
cin>>k>>l>>p>>s>>w;
k%=p;
if(l==1){
if(s)cout<<(ll)1%p;
else cout<<k%p;
}else if(s){
cout<<(k-1)%p*(ksm(k-2,l-2,p)%p)%p;
}else{
cout<<k%p*(k-1)%p*(ksm(k-2,l-2,p)%p)%p;
}
return 0;
}