题解:P7392 「TOCO Round 1」奇怪的排序
wu15874985920 · · 题解
思路
处理多组数据输入,每组数据包含情人数
当
当
使用 long long 类型避免整数溢出。
每次乘法后取模
时间复杂度
代码
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
int T;
cin >> T;
while (T--) {
int n, k;
cin >> n >> k;
if (k == 1) {
cout << 1 << endl;
} else {
long long ans = 1;
for (int i = 1; i <= n; ++i) {
ans = ans * (n - i + 1) % MOD;
}
cout << ans << endl;
}
}
return 0;}