10月5日普及组改错

· · 题解

第一、三、四、五、题太简单了,一不小心就AC了

第二题

:::info[题目传送门]

排队打饭

lineup.cpp

题目描述

暑期集训共有 n 名选手。Z 老师计划让其中 m 人先去打饭,其余同学在机房等待。

他想知道有多少种不同的打饭顺序。由于结果可能很大,请输出模 1000000007 的结果。

输入格式

第一行输入两个正整数 n 和 m。

输出格式

输出排队方案数。
### 思路
> 通过 拉马努金瞪眼法 可知,题目是让我们算A_{n}^{m}
通过化简可知,A_{n}^{m}=n \times (n-1) \times (n-2) \times … \times (n-m+1)
### 错因

:::success[AC CODE]

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod =  1000000007;
ll n, m;
ll ans = 1;
int main() {
    cin >> n >> m;
    for (ll i = 0; i < m; i++) {
        ans = (ans * ((n - i)%mod)) % mod;
    }
    cout << ans;
    return 0;
}

:::

第六题

:::info[题目传送门]

约数个数

divisor.cpp

题目描述

约数的个数即能够整除正整数 n 的数的个数。例如 n 为 10 时,n 的约数个数为 1, 2, 5, 10 共 4 个。

小西在学完数论基础后,对于阶乘 n! 非常感兴趣,他想知道 n! 约数的个数是多少。

输入格式

输入一个正整数 n,表示 n 的阶乘。

输出格式

输出一个正整数表示答案。
### 思路
> 又是拉马努金瞪眼法
一眼锁定唯一分解定理:n=p_{1}^{a_1} \times p_{2}^{a_2} \times p_{3}^{a_3} \times … \times p_{m}^{a_m}
用d(n)表示n的约数个数,则d(n)=(a_1+1) \times (a_2+1) \times … \times (a_m+1)
对于 n! 可以将 1 至 n 中的每一个元素进行唯一分解,用桶统计每个质因数的出现次数。该出现次数的元素即为 a_i 。
再用计算 d(n) 的公式求解即可
### 错因
没想到(忘了)要用唯一分解定理
:::success[AC CODE]
```cpp line-numbers
#include<bits/stdc++.h>
using namespace std;
typedef __int128 lll;
void write(lll x) {
if (x == 0) return;
if (x < 0) {
cout << '-';
x = -x;
}
write(x / 10);
cout << (int)(x % 10);
}
int main() {
int n;
cin >> n;
int cnt[105] = {0};
for (int i = 2; i <= n; i++) {
int asd = i;
for (int j = 2; j * j <= asd; j++) {
while (asd % j == 0) {
cnt[j]++;
asd /= j;
}
}
if (asd > 1) cnt[asd]++;
}
lll ans = 1;
for (int i = 2; i <= n; i++) {
if (cnt[i] > 0) {
ans *= (cnt[i] + 1);
}
}
if (ans == 0) cout << 0;
else write(ans);
cout << endl;
return 0;
}
```
:::
创作不易,求关