跳到正文

题解

10月5日普及组改错

xiangchuancyl约 4 分钟
原文
文章信息与版本

文章信息

发布
2026年10月5日
收录
2026年10月6日
更新
2026年11月11日
篇幅
约 4 分钟

版本

  1. v1当前

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

第二题

题目传送门

排队打饭

lineup.cpp

题目描述

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

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

输入格式

第一行输入两个正整数 nn 和 mm。

输出格式

输出排队方案数。

思路

通过 拉马努金瞪眼法 可知,题目是让我们算AnmA_{n}^{m}
通过化简可知,Anm=n×(n−1)×(n−2)×…×(n−m+1)A_{n}^{m}=n \times (n-1) \times (n-2) \times … \times (n-m+1)

错因

AC CODE
C++
#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;
}

第六题

题目传送门

约数个数

divisor.cpp

题目描述

约数的个数即能够整除正整数 nn 的数的个数。例如 nn 为 1010 时,nn 的约数个数为 1,2,5,101, 2, 5, 10 共 44 个。

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

输入格式

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

输出格式

输出一个正整数表示答案。

思路

又是拉马努金瞪眼法
一眼锁定唯一分解定理:n=p1a1×p2a2×p3a3×…×pmamn=p_{1}^{a_1} \times p_{2}^{a_2} \times p_{3}^{a_3} \times … \times p_{m}^{a_m}
用d(n)d(n)表示nn的约数个数,则d(n)=(a1+1)×(a2+1)×…×(am+1)d(n)=(a_1+1) \times (a_2+1) \times … \times (a_m+1)
对于 n!n! 可以将 11 至 nn 中的每一个元素进行唯一分解,用桶统计每个质因数的出现次数。该出现次数的元素即为 aia_i 。 再用计算 d(n)d(n) 的公式求解即可

错因

没想到(忘了)要用唯一分解定理

AC CODE
C++
#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;
}

创作不易,求关

原文