10月5日普及组改错
xiangchuancyl · · 题解
第一、三、四、五、题太简单了,一不小心就AC了
第二题
:::info[题目传送门]
排队打饭
lineup.cpp
题目描述
暑期集训共有
他想知道有多少种不同的打饭顺序。由于结果可能很大,请输出模
输入格式
第一行输入两个正整数
输出格式
| 输出排队方案数。 |
|---|
| ### 思路 |
| > 通过 |
| 通过化简可知, |
| ### 错因 |
:::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
题目描述
约数的个数即能够整除正整数
小西在学完数论基础后,对于阶乘
输入格式
输入一个正整数
输出格式
| 输出一个正整数表示答案。 |
|---|
| ### 思路 |
| > |
| 一眼锁定唯一分解定理: |
| 用 |
| 对于 |
| 再用计算 |
| ### 错因 |
| 没想到( |
| :::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; |
| } |
| ``` |
| ::: |