跳到正文

个人记录

改错

LYZ24约 8 分钟
原文
文章信息与版本

文章信息

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

版本

  1. v2当前
  2. v1
5

1.题目大意:

计算 n∗nn * n 的正方形中长方形的个数(不包括正方形)。

2.思路:

递推:
令 fi\large f_i 表示前 ii 行共有多少个矩形(包括正方形),gi\large g_i 表示前 ii 行共有多少个正方形,则 ans=fn−gn\large ans = f_n - g_n。

由画图可知,用上半部分加下半部分加合并部分即可,f1=(n∗n−n)/2+n\large f_1 = (n * n - n) / 2 + n,
fi=fi−1+f1+f1∗(i−1)\large f_i = f_{i - 1} + f_1 + f_1 * (i-1)。 由画图可知,用上半部分加下半部分加合并部分计算:
g1=n\large g_1 = n,
gi=gi−1+g1+n∗(i−1)−(i∗i−i)/2\large g_i = g_{i - 1} + g_1 + n * (i - 1) - (i * i - i) / 2
ps:注意中间部分不是从 11 加到 nn 而是到 i−1i - 1。

3.代码:

C++
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N = 1e5 + 50;
ull n;
ull f[N], g[N];
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("rec.in", "r", stdin);
//	freopen("rec.out", "w", stdout);
	cin >> n;
	f[1] = (n * n - n) / 2 + n;
	g[1] = n;
	for (ull i = 2; i <= n; ++i) {
		f[i] = f[1] + f[i - 1] + f[1] * (i - 1);
		g[i] = g[i - 1] + g[1] + n * (i - 1) - (i *  i - i) / 2;
	}
	cout << f[n] - g[n];
	return 0;
}

ps:好像要开**__int128**。

第 1 题: square 平方数                                                                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1.题目大意:

求一个数的最大的平方约数。

2.思路:

枚举平方数。

3.代码:

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("square.in", "r", stdin);
//	freopen("square.out", "w", stdout);
	cin >> n;
	for (ll i = (ll)sqrt(n); i >= 1; --i) {
		if (n % (i * i) == 0) {
			cout << i * i;
			return 0;
		}
	}
	return 0;
}
2

1.题目大意:

从 n\large n 个人中选出 m\large m 个人排队打饭,求排列方案数。

2.思路:

求 Anm\large A_n^m。

3.代码:

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
ll n, m, res = 1;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("lineup.in", "r", stdin);
//	freopen("lineup.out", "w", stdout);
	cin >> n >> m;
	for (ll i = n; i >= n - m + 1; --i) {
		(res *= (i % MOD)) %= MOD;
	}
	cout << res;
	return 0;
}

ps: 错因:
未对 ii 取模。

3

1.题目大意:

求第 kk 个优美数。
(优美数指含有 77 或是 77 的倍数的数)

2.思路:

打表(离线)。

3.代码:

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 50;
ll t, k[N], cnt, ans, n;
ll a[N];
bool check(ll x) {
	if (x % 7 == 0) return 1;
	while (x) {
		if (x % 10 == 7) return 1;
		x /= 10;
	}
	return 0;
}
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("beauty.in", "r", stdin);
//	freopen("beauty.out", "w", stdout);
	cin >> t;
	for (int i = 1; i <= t; ++i) cin >> k[i], n = max(n, k[i]);
	for (int i = 1; cnt < n; ++i) {
		if (check(i)) {
			a[++cnt] = i;
		}
	}
	for (int i = 1; i <= t; ++i) {
		cout << a[k[i]] << "\n";
	}
	return 0;
}
第 4 题: hundred 倍数                                                                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1.题目大意:

在数组 aa 中找到两个数使得差为 100100 的倍数(包括 00)。

2.思路:

将 ai\large a_i 对 100100 取模,存入桶中,对于每个数量 p\large p 多于 11 的桶累加 (p2+p)/2(p^2 + p) / 2 的贡献。

3.代码:

C++
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N = 150;
ull n, a[N];
ull ans;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("hundred.in", "r", stdin);
//	freopen("hundred.out", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int cn;
		cin >> cn;
		a[cn % 100]++;
	}
	for (int i = 0; i < 100; ++i) {
		if (a[i] > 1) {
			ans += a[i] * (a[i] - 1) / 2;
		}
	}
	cout << ans;
	return 0;
}

ps错因:
未使用桶记录。

6

1.题目大意:

求阶乘的约数个数。

2.思路:

唯一分解后将所有指数加 11 后累乘。

3.代码:

C++
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N = 1e5 + 50;
int n;
int a[150];
ull ans = 1;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int man = 2; man <= n; ++man) {
		int qq = man;
		for (int i = 2; i <= qq / i; ++i) {
			if (qq % i == 0) {
				while (qq % i == 0) {
					a[i]++;
					qq /= i;
				}
			}
		}
		if (qq > 1) {
			a[qq]++;
		}
	}
	for (int i = 1; i <= 100; ++i) {
		ans *= (a[i] + 1);
	}
	cout << ans;
	return 0;
}
原文