Luogu P10532 [XJTUPC 2024] 筛法 题解 [ 绿 ] [ 组合意义 ] [ 欧拉函数 ] [ Ad-hoc ]
P10532 [XJTUPC 2024] 筛法:再来点神秘组合意义。
这题推式子做法需要用到欧拉函数相关知识,直接爆算也需要杜教筛之类的科技。打表做法是最简单的,写个 \(O(n^2)\) 暴力就很容易能发现答案就是 \(n^2\)。
证明可以考虑组合意义,问题转化为求所有互质数对 \((i,j)\) 的价值之和,一个数对的价值定义为 \(\dfrac{n}{\max(i,j)}\)。发现 \(\dfrac{n}{\max(i,j)}\) 相当于将 \((i,j)\) 变成 \((ki,kj)\) 后满足 \(ki,kj\le n\) 的 \(k\) 的个数。于是每个非互质数对 \((i,j)\) 都可以放在 \((\dfrac{i}{\gcd(i,j)}, \dfrac{j}{\gcd(i,j)})\) 处计数。于是答案就是 \(n^2\)。
时间复杂度 \(O(1)\)。
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb(x) emplace_back(x)
#define pb(x) push_back(x)
#define lc(x) (tr[x].ls)
#define rc(x) (tr[x].rs)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
using pi = pair<int, int>;
ll n;
int main()
{
//freopen("sample.in", "r", stdin);
//freopen("sample.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
cout << n * n;
return 0;
}

浙公网安备 33010602011771号