这题就是一个 找规律+快速幂
在这里放上一篇dalao的博客吧
https://blog.nowcoder.net/n/d97211980f9a4338b6aad39c94e8eec2?f=comment
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
ll pow_mod(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1)
ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
int main() {
ll n;cin >> n;
if (n == 1) cout << "0" << endl;
else if (n == 2) cout << "1" << endl;
else if (n == 3) cout << "6" << endl;
else cout << (((n % mod) * ((n - 1) % mod)) % mod * pow_mod(2, n - 3) % mod) % mod << endl;
return 0;
}