#include <iostream>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long unsigned n,m,ll=1000000007,x=1;
cin>>n>>m;
if (n<2)
{cout<<"0";
return 0;}
if (m==1)
{cout<<"1";
return 0;}
if (n==2)
{cout<<m%ll;}
if (n==3)
{cout<<(m*3)%ll;
return 0;}
if (m==2)
{
x=1;
for (int i=0;i<n;i++)
{x=(x*2)%ll;}
x=(x-(2*(n-1)))%ll;
if (x<0) {x=x+ll;}
cout<<x;
return 0;
}
if (n==4)
{x=(m*m*m)%ll+(m*(m-1))%ll;
cout<<x;
return 0;
}
if (n==5)
{x=((m*m*m*m)%ll+(m*m*(m-1)*2)%ll)%ll;
cout<<x;
return 0;
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long unsigned n,m,ll=1000000007,x=1; cin>>n>>m; if (n<2) {cout<<"0"; return 0;} if (m==1) {cout<<"1"; return 0;} if (n==2) {cout<<m%ll;} if (n==3) {cout<<(m*3)%ll; return 0;} if (m==2) { x=1; for (int i=0;i<n;i++) {x=(x*2)%ll;} x=(x-(2*(n-1)))%ll; if (x<0) {x=x+ll;} cout<<x; return 0; } if (n==4) {x=(m*m*m)%ll+(m*(m-1))%ll; cout<<x; return 0; } if (n==5) {x=((m*m*m*m)%ll+(m*m*(m-1)*2)%ll)%ll; cout<<x; return 0; } return 0; } |
English