分情况:
第一盆k种选择,之后全部k-1种选择
每次相乘结果对1e9+7取模
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define endl '\n'
const int N = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t, n, k;
cin >> t;
while (t--) {
long long sum = 1;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
if (i == 1) sum *= k;
else {
sum *= k - 1;
sum %= N;
}
}
cout << sum << endl;
}
return 0;
}