正文
增加 20 行删除 10 行
123418 行未改动2324252627282930313273 行未改动10610710810911011111211318 行未改动13213313413513613713813914074 行未改动21521621721821922022122233 行未改动25625725825926026126226326468 行未改动33333433533633733833934022 行未改动36336436536636736836937037151 行未改动42342442542642742842943012 行未改动443444445446447448449450451121 行未改动全部展开57357457557657757857958027 行未改动60860961061161261361461561683 行未改动70070170270370470570670770870971071171271371471543 行未改动75976076176276376476576622 行未改动789790791792793794795796797191 行未改动全部展开98999099199299399499599623 行未改动10201021102210231024102510261027102881 行未改动1110111111121113## [A Luogu P1891](https://www.luogu.com.cn/problem/P1891)### 题目求$$18 行未改动Ans = n \sum_{d | n}{\frac{\varphi(\frac{n}{d}) \frac{n}{d}}{2}} \\= n \sum_{d | n}{\frac{\varphi(d) d}{2}}$$欧拉筛预处理欧拉函数枚举因数计算答案即可。时间复杂度 $O(n + T \sqrt{n})$。### AC Code```cpp#include<bits/stdc++.h>using namespace std;#define ll long long73 行未改动while(T--)solve();return 0;}```## [B Luogu P2257](https://www.luogu.com.cn/problem/P2257)### 题目求$$18 行未改动\end{align*}$$此时后面的和式已经和前面无关了,可以预处理,前面的是一个下取整式,于是直接二维整除分块即可。时间复杂度 $O(n \log \log n + T \sqrt{n})$。### AC Code```cpp#include<bits/stdc++.h>using namespace std;#define ll long long74 行未改动while(T--)solve();return 0;}```## [C Luogu P2260](https://www.luogu.com.cn/problem/P2260)### 题目求$$33 行未改动\end{align*}$$对每个和式分别写一个数论分块即可。时间复杂度 $O(\sqrt{n} + \sqrt{m})$。### AC Code```cpp#include<bits/stdc++.h>using namespace std;#define ll long long68 行未改动write((Ans+mod)%mod);return 0;}```## [D Luogu P2303](https://www.luogu.com.cn/problem/P2303)### 题目求$$22 行未改动&=\prod_{p | n}{\frac{n_p p - n_p + p}{p}}\end{align*}$$时间复杂度 $O(\sqrt{n})$。### AC Code```cpp#include<bits/stdc++.h>using namespace std;#define ll long long51 行未改动write(ans);return 0;}```## [E Luogu P3312](https://www.luogu.com.cn/problem/P3312)### 题目有一张 $n \times m$ 的数表,其第 $i$ 行第 $j$ 列($1\le i\le n$,$1\le j\le m$)的数值为能同时整除 $i$ 和 $j$ 的所有自然数之和。给定 $a$,计算数表中不大于 $a$ 的数之和。$n , m \le 10^5 , q \le 2 \times 10^4$。12 行未改动$$这个时候已经可以数论分块做了。下面来考虑 $a$ 的限制。我们发现后面的这个和式是跟 $\sigma(d)$ 有关的,那么代表着只有在 $\sigma(d)$ 小于等于 $a$ 的时候才会对这个和式产生贡献,那么我们考虑离线所有询问,按 $a$ 排序,用一种数据结构维护单点改和区间和,每次询问前把新增的会产生贡献的数加进来。时间复杂度 $O(n \ln n + q \sqrt{n})$。### AC Code```cpp#include<bits/stdc++.h>using namespace std;#define ll long long121 行未改动全部展开for(int i=1;i<=q;++i)write(ans[i]%mod),write('\n');return 0;}```## [F Luogu P3327](https://www.luogu.com.cn/problem/P3327)### 题目设 $d(x)$ 为 $x$ 的约数的个数,求$$27 行未改动\sum_{k = 1}^{n}{\mu(k) f(\lfloor \frac{n}{k} \rfloor) f(\lfloor \frac{m}{k} \rfloor)}$$然后预处理 $f$ 的值,做二维数论分块即可。时间复杂度 $O(n \sqrt{n} + q \sqrt{n})$。### AC Code```cpp#include<bits/stdc++.h>using namespace std;#define ll long long83 行未改动while(T--)solve();return 0;}```## [G Luogu P5150](https://www.luogu.com.cn/problem/P5150)### 题目给定 $n$,求有多少对正整数 $(i,j)$ 的 $\operatorname{lcm}$ 是 $n$。$n \le 10^{16}$。### Solution考虑质因数分解,$n = \prod_{p}{p^{n_p}}$,那么 $\operatorname{lcm}(i,j) = n$ 的充要条件是 $\forall p , \max(i_p,j_p) = n_p$,那么对于所有质数是独立的,简单容斥得到对于某一个质数的选择方案数是 $2 n_p + 1$,根据乘法原理求积即可。时间复杂度 $O(\sqrt{n})$。### AC Code```cpp#include<bits/stdc++.h>using namespace std;#define ll long long43 行未改动write(ans);return 0;}```## [H Luogu P6222](https://www.luogu.com.cn/problem/P6222)[Luogu P6156](https://www.luogu.com.cn/problem/P6156)加强版### 题目$$22 行未改动$$和式通过预处理前缀和递推即可。此时就可以数论分块做了。时间复杂度 $O(n + T \sqrt{n})$。### AC Code普通版```cpp#include<bits/stdc++.h>using namespace std;191 行未改动全部展开while(T--)solve();return 0;}```## [I AT_agc038_c](https://atcoder.jp/contests/agc038/tasks/agc038_c)### 题目给定 $n$ 个正整数 $a_1 \cdots a_n$,求$$23 行未改动\end{align*}$$现在,我们发现第一个和式是一个积性函数,直接筛即可。第二个是一个调和级数复杂度预处理的东西,最后枚举 $t$ 统计答案即可。时间复杂度 $O(V \ln V)$。### AC Code```cpp#include<bits/stdc++.h>using namespace std;#define ll long long81 行未改动write((ans+mod)%mod);return 0;}```1234518 行未改动2425262728293031323373 行未改动10710810911011111211311411518 行未改动13413513613713813914014114274 行未改动21721821922022122222322422533 行未改动25926026126226326426526626768 行未改动33633733833934034134234334422 行未改动36736836937037137237337437551 行未改动42742842943043143243343443512 行未改动448449450451452453454455456121 行未改动全部展开57857958058158258358458558627 行未改动61461561661761861962062162283 行未改动70670770870971071171271371471571671771871972072172243 行未改动76676776876977077177277377422 行未改动797798799800801802803804805191 行未改动全部展开99799899910001001100210031004100523 行未改动10291030103110321033103410351036103781 行未改动11191120112111221123upd:2026-10-14 给代码加了折叠框## [A Luogu P1891](https://www.luogu.com.cn/problem/P1891)### 题目求$$18 行未改动Ans = n \sum_{d | n}{\frac{\varphi(\frac{n}{d}) \frac{n}{d}}{2}} \\= n \sum_{d | n}{\frac{\varphi(d) d}{2}}$$欧拉筛预处理欧拉函数枚举因数计算答案即可。时间复杂度 $O(n + T \sqrt{n})$。::::info[**AC Code**]```cpp#include<bits/stdc++.h>using namespace std;#define ll long long73 行未改动while(T--)solve();return 0;}```::::## [B Luogu P2257](https://www.luogu.com.cn/problem/P2257)### 题目求$$18 行未改动\end{align*}$$此时后面的和式已经和前面无关了,可以预处理,前面的是一个下取整式,于是直接二维整除分块即可。时间复杂度 $O(n \log \log n + T \sqrt{n})$。::::info[**AC Code**]```cpp#include<bits/stdc++.h>using namespace std;#define ll long long74 行未改动while(T--)solve();return 0;}```::::## [C Luogu P2260](https://www.luogu.com.cn/problem/P2260)### 题目求$$33 行未改动\end{align*}$$对每个和式分别写一个数论分块即可。时间复杂度 $O(\sqrt{n} + \sqrt{m})$。::::info[**AC Code**]```cpp#include<bits/stdc++.h>using namespace std;#define ll long long68 行未改动write((Ans+mod)%mod);return 0;}```::::## [D Luogu P2303](https://www.luogu.com.cn/problem/P2303)### 题目求$$22 行未改动&=\prod_{p | n}{\frac{n_p p - n_p + p}{p}}\end{align*}$$时间复杂度 $O(\sqrt{n})$。::::info[**AC Code**]```cpp#include<bits/stdc++.h>using namespace std;#define ll long long51 行未改动write(ans);return 0;}```::::## [E Luogu P3312](https://www.luogu.com.cn/problem/P3312)### 题目有一张 $n \times m$ 的数表,其第 $i$ 行第 $j$ 列($1\le i\le n$,$1\le j\le m$)的数值为能同时整除 $i$ 和 $j$ 的所有自然数之和。给定 $a$,计算数表中不大于 $a$ 的数之和。$n , m \le 10^5 , q \le 2 \times 10^4$。12 行未改动$$这个时候已经可以数论分块做了。下面来考虑 $a$ 的限制。我们发现后面的这个和式是跟 $\sigma(d)$ 有关的,那么代表着只有在 $\sigma(d)$ 小于等于 $a$ 的时候才会对这个和式产生贡献,那么我们考虑离线所有询问,按 $a$ 排序,用一种数据结构维护单点改和区间和,每次询问前把新增的会产生贡献的数加进来。时间复杂度 $O(n \ln n + q \sqrt{n})$。::::info[**AC Code**]```cpp#include<bits/stdc++.h>using namespace std;#define ll long long121 行未改动全部展开for(int i=1;i<=q;++i)write(ans[i]%mod),write('\n');return 0;}```::::## [F Luogu P3327](https://www.luogu.com.cn/problem/P3327)### 题目设 $d(x)$ 为 $x$ 的约数的个数,求$$27 行未改动\sum_{k = 1}^{n}{\mu(k) f(\lfloor \frac{n}{k} \rfloor) f(\lfloor \frac{m}{k} \rfloor)}$$然后预处理 $f$ 的值,做二维数论分块即可。时间复杂度 $O(n \sqrt{n} + q \sqrt{n})$。::::info[**AC Code**]```cpp#include<bits/stdc++.h>using namespace std;#define ll long long83 行未改动while(T--)solve();return 0;}```::::## [G Luogu P5150](https://www.luogu.com.cn/problem/P5150)### 题目给定 $n$,求有多少对正整数 $(i,j)$ 的 $\operatorname{lcm}$ 是 $n$。$n \le 10^{16}$。### Solution考虑质因数分解,$n = \prod_{p}{p^{n_p}}$,那么 $\operatorname{lcm}(i,j) = n$ 的充要条件是 $\forall p , \max(i_p,j_p) = n_p$,那么对于所有质数是独立的,简单容斥得到对于某一个质数的选择方案数是 $2 n_p + 1$,根据乘法原理求积即可。时间复杂度 $O(\sqrt{n})$。::::info[**AC Code**]```cpp#include<bits/stdc++.h>using namespace std;#define ll long long43 行未改动write(ans);return 0;}```::::## [H Luogu P6222](https://www.luogu.com.cn/problem/P6222)[Luogu P6156](https://www.luogu.com.cn/problem/P6156)加强版### 题目$$22 行未改动$$和式通过预处理前缀和递推即可。此时就可以数论分块做了。时间复杂度 $O(n + T \sqrt{n})$。::::info[**AC Code**]普通版```cpp#include<bits/stdc++.h>using namespace std;191 行未改动全部展开while(T--)solve();return 0;}```::::## [I AT_agc038_c](https://atcoder.jp/contests/agc038/tasks/agc038_c)### 题目给定 $n$ 个正整数 $a_1 \cdots a_n$,求$$23 行未改动\end{align*}$$现在,我们发现第一个和式是一个积性函数,直接筛即可。第二个是一个调和级数复杂度预处理的东西,最后枚举 $t$ 统计答案即可。时间复杂度 $O(V \ln V)$。::::info[**AC Code**]```cpp#include<bits/stdc++.h>using namespace std;#define ll long long81 行未改动write((ans+mod)%mod);return 0;}```::::