题意

求 $$\displaystyle \sum_{i=1}^{n} \sum_{j=1}^{n} [\mathrm{lcm} (i,j) > n] \pmod {10^9 + 7}$$ .

$ n \le 10^{10}$ .

题解

这是我们考试的一道题 ... 考试的时候以为能找出规律 , 后来发现还是一道数论题 qwq

而且部分分很不良心啊 , 只给了 \(O(n)\) 多的一点分 , 我 \(O(n \ln n)\) 根本没活路 .. 还是直接开始推吧 ~

\[\begin{align}
\sum_{i=1}^{n} \sum_{j=1}^{n} [\mathrm{lcm} (i,j) > n] &=n^2- \sum_{i=1}^{n} \sum_{j=1}^{n} [\mathrm{lcm} (i,j) \le n]\\
&= n^2 - \sum_{d=1}^{n} \sum_{i=1}^{\lfloor \frac{n}{d} \rfloor} \sum_{j=1}^{\lfloor \frac{n}{d} \rfloor} [ijd \le n] \cdot [i \bot j] \\
&= n^2 - \sum_{d=1}^{n} \sum_{i=1}^{\lfloor \frac{n}{d} \rfloor} \sum_{j=1}^{\lfloor \frac{n}{d} \rfloor}[ijd \le n] \sum_{x|(i,j)}\mu(x) \\
&= n^2 - \sum_{d=1}^{n} \sum_{x=1}^{\lfloor \frac{n}{d}\rfloor} \mu(x) \sum_{i=1}^{\lfloor \frac{n}{dx} \rfloor} \sum_{j=1}^{\lfloor \frac{n}{dx} \rfloor}[ijdx^2 \le n] \\
&= n^2 - \sum_{x=1}^{n} \mu(x) \sum_{d=1}^{\lfloor \frac{n}{x} \rfloor} \sum_{i=1}^{\lfloor \frac{n}{dx} \rfloor} \sum_{j=1}^{\lfloor \frac{n}{dx} \rfloor}[ijdx^2 \le n] \\
\end{align}
\]

到这一步不难发现由于 \([ijdx^2 \le n]\) 可以缩减很多范围了 比如 \(x \le \lfloor \sqrt n \rfloor\) ... 直接一波缩范围

\[\displaystyle = n^2 - \sum_{x=1}^{\lfloor \sqrt n \rfloor} \mu(x) \sum_{d=1}^{\lfloor \frac{n}{x^2} \rfloor} \sum_{i=1}^{\lfloor \frac{n}{dx^2} \rfloor} \sum_{j=1}^{\lfloor \frac{n}{dx^2} \rfloor}[ij \le \lfloor \frac{n}{dx^2} \rfloor]
\]

我们可以考虑看一下后面两个 \(\sum\) 好像很有特点。令

\[\displaystyle f(x) = \sum_{i=1}^{x} \sum_{j=1}^{x} [ij \le x]
\]

那么原式就是

\[\displaystyle = n^2 - \sum_{x=1}^{\lfloor \sqrt n \rfloor} \mu(x) \sum_{d=1}^{\lfloor \frac{n}{x^2} \rfloor} f(\lfloor \frac{n}{dx^2} \rfloor)
\]

观察一下 \(f(x)\) 好像也可以进行转化

考虑枚举一个 \(i,j\) 的积 , 看有多少对 \((i,j)\) 可以 .

\[\displaystyle f(x) = \sum_{d=1}^{x} \lfloor \frac{x}{d} \rfloor
\]

这个容易在 \(O(\sqrt n)\) 直接分块解决 . 这样带入直接做就有 60 分了 \((n \le 10^8)\) , 不会积分证明复杂度QAQ ....

卡一卡 , 在本机上能跑 \(10^9\) 能拿80分 爽歪歪 qwq

后来我意识到瓶颈在 \(f(x)\) 处 , 各种问人是否有公式计算 .... 后来才发现 这个竟然是今年集训队论文 ??!!!

**《一些特殊的数论函数求和问题》 —— 安徽师范大学附属中学 朱震霆 **

考虑我最初的那个式子

\[\displaystyle f(n) = \sum_{i=1}^{n} \sum_{j=1}^{n} [ij \le n]
\]

难道不就是数 \(xy=n\) 下面的整点个数吗 !!

我认真看了论文许久,可还是看不懂,只知道大概就是用很多根切线去分割,然后去数切线下方的点.

过几天看懂了再来理解 .... 只知道复杂度是 \(O(n^{\frac{1}{3}})\) 的,十分优秀 ~

然后直接找到 whzzt 的代码 ,尝试着放进去我的程序...

竟然过了!!!跑了 \(0.5s\) 就过了.... (原来要跑 \(6s\) )

挂一波代码就跑 qwq

代码

#include <bits/stdc++.h>
#define For(i, l, r) for (register ll i = (ll)(l), i##end = (ll)(r); i <= i##end; ++ i)
#define Fordown(i, r, l) for (register ll i = (ll)(r), i##end = (ll)(l); i >= i##end; -- i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std; typedef long long ll;
inline bool chkmin(ll &a, ll b) { return b < a ? a = b, 1 : 0; }
inline bool chkmax(ll &a, ll b) { return b > a ? a = b, 1 : 0; } inline ll read() {
ll x = 0, fh = 1; char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
return x * fh;
} void File() {
freopen ("ra.in", "r", stdin);
freopen ("ra.out", "w", stdout);
} const ll Mod = 1e9 + 7; const ll N = 1e6 + 1e3;
ll mu[N], prime[N], cnt = 0; bitset<N> is_prime;
void Init(ll maxn) {
is_prime.set(); is_prime[0] = is_prime[1] = false; mu[1]= 1;
For (i, 2, maxn) {
if (is_prime[i])
prime[++ cnt] = i, mu[i] = -1;
For (j, 1, cnt) {
ll res = prime[j] * i;
if (res > maxn) break ;
is_prime[res] = false;
if (i % prime[j]) mu[res] = - mu[i];
else { mu[res] = 0; break ; }
}
}
} /*inline ll SumDown(ll a) {
ll res = M[a]; if (res) return res;
For (i, 1, a) {
register ll now = a / i, Nexti = a / now;
res += now * (Nexti - i + 1); i = Nexti;
}
return (M[a] = res % Mod);
}*/ typedef unsigned long long uLL;
typedef unsigned long long ull;
typedef unsigned int uint; unordered_map<ull, uLL> M;
namespace ds {
namespace stac {
const int N = 100005;
uint qu[N][2]; int qr;
inline void pop () { qr --; }
inline void push (uint x, uint y) { qr ++; qu[qr][0] = x; qu[qr][1] = y; }
inline void top (uint &x, uint &y) { x = qu[qr][0]; y = qu[qr][1]; }
}
using stac :: push;
using stac :: pop;
using stac :: top; inline uLL solve (ull n) {
uLL ret = M[n];
if (ret) return ret;
ull w = pow (n, 0.38), v = sqrtl (n), x, y;
uint dx, dy, ux, uy, mx, my;
while (v * v <= n) v ++; while (v * v > n) v --;
x = n / v, y = n / x + 1;
push (1, 0); push (1, 1);
auto outside = [&] (ull x, ull y) { return x * y > n; };
auto cut_off = [&] (ull x, uint dx, uint dy) { return (uLL)x * x * dy >= (uLL)n * dx; };
while (stac :: qr) {
top (dx, dy);
while (outside (x + dx, y - dy)) {
ret += x * dy + ull(dy + 1) * (dx - 1) / 2;
x += dx, y -= dy;
}
if (y <= w) break;
while (true) {
pop (), ux = dx, uy = dy, top (dx, dy);
if (outside (x + dx, y - dy)) break;
}
while (true) {
mx = ux + dx, my = uy + dy;
if (!outside (x + mx, y - my)) {
if (cut_off (x + mx, dx, dy)) break;
ux = mx, uy = my;
} else push (dx = mx, dy = my);
}
}
for (y --; y; y --) ret += n / y;
return stac :: qr = 0, (M[n] = ret * 2 - v * v);
}
} int main() {
File();
ll n = read(), res = 0;
Init(1e6); For (x, 1, sqrt(n)) if (mu[x]) {
register ll Lim = n / (x * x), tot = 0;;
For (d, 1, Lim) {
register ll now = Lim / d, Nextd = Lim / now;
tot += ds :: solve(now) * (Nextd - d + 1); d = Nextd;
}
(res += Mod + tot % Mod * mu[x]) %= Mod;
} res = ((n % Mod) * (n % Mod) % Mod - res + Mod) % Mod; cout << res << endl; #ifdef zjp_shadow
cerr << (double) clock() / CLOCKS_PER_SEC << endl;
#endif return 0;
}

ra (数论 , 莫比乌斯反演 , 整点统计)的更多相关文章

  1. 【BZOJ4176】Lucas的数论 莫比乌斯反演

    [BZOJ4176]Lucas的数论 Description 去年的Lucas非常喜欢数论题,但是一年以后的Lucas却不那么喜欢了. 在整理以前的试题时,发现了这样一道题目“求Sigma(f(i)) ...

  2. [SPOJ VLATTICE]Visible Lattice Points 数论 莫比乌斯反演

    7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0, ...

  3. 51Nod1675 序列变换 数论 莫比乌斯反演

    原文http://www.cnblogs.com/zhouzhendong/p/8665675.html 题目传送门 - 51Nod1675 题意 给定序列$a,b$,让你求满足$\gcd(x,y)= ...

  4. UOJ#62. 【UR #5】怎样跑得更快 数论 莫比乌斯反演

    原文链接https://www.cnblogs.com/zhouzhendong/p/UOJ62.html 题解 太久没更博客了,该拯救我的博客了. $$\sum_{1\leq j \leq n} \ ...

  5. 【bzoj3601】一个人的数论 莫比乌斯反演+高斯消元

    题目描述 题解 莫比乌斯反演+高斯消元 (前方高能:所有题目中给出的幂次d,公式里为了防止混淆,均使用了k代替) #include <cstdio> #include <cstrin ...

  6. 【bzoj4176】Lucas的数论 莫比乌斯反演+杜教筛

    Description 去年的Lucas非常喜欢数论题,但是一年以后的Lucas却不那么喜欢了. 在整理以前的试题时,发现了这样一道题目"求Sigma(f(i)),其中1<=i< ...

  7. 组合 数论 莫比乌斯反演 hdu1695

    题解:https://blog.csdn.net/lixuepeng_001/article/details/50577932 题意:给定范围1-b和1-d求(i,j)=k的数对的数量 #includ ...

  8. 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)

    题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...

  9. BZOJ 4176 Lucas的数论 莫比乌斯反演+杜教筛

    题意概述:求,n<=10^9,其中d(n)表示n的约数个数. 分析: 首先想要快速计算上面的柿子就要先把d(ij)表示出来,有个神奇的结论: 证明:当且仅当a,b没有相同的质因数的时候我们统计其 ...

随机推荐

  1. BZOJ 2784 时间流逝

    BZOJ 2784 时间流逝 古典概率论... 可以发现由于能量圈数量限制,所以所构成的必定为树状结构(即便是转成最小能量圈和能量圈权值和之后存在重复状态,但是每个状态的含义不同,而且不能自身转移自身 ...

  2. 3.4《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)——grepping(检索目标行命令)

    grep是检查文件内容最强大的工具之一,这也许不能代表什么,但这不是重点.的确,grep常用作动词,比如'你完全应该检索(grep)那个文件'. grep最常用于在文件中搜索子字符串.例如,我们在第三 ...

  3. UOJ219 NOI2016 优秀的拆分 二分、字符串哈希

    传送门 题目可以转化为求\(AA\)的数量,设\(cnt1_x\)表示左端点为\(x\)的\(AA\)的数量,\(cnt2_x\)表示右端点为\(x\)的\(AA\)的数量,那么答案就是\(\sum ...

  4. React-异步组件及withRouter路由方法的使用

    所有组件的代码都打包在bundle.js里,加载首页的时候,把其它页面的代码也加载了,影响首页加载速度.我们希望访问首页的时候只加载首页,访问详情页的时候再去加载详情页的代码.异步组件可以帮我们实现, ...

  5. Trusted Block Chain Summit(2018.10.09)

    时间:2018.10.09地点:北京金隅喜来登大酒店

  6. NPOI导Excel样式设置

    一.创建一个Excel //创建一个工作簿 XSSFWorkbook workbook = new XSSFWorkbook(); //创建一个页 ISheet sheet = workbook.Cr ...

  7. 数列分块入门九题(三):LOJ6283~6285

    Preface 最后一题我一直觉得用莫队是最好的. 数列分块入门 7--区间乘法,区间加法,单点询问 还是很简单的吧,比起数列分块入门 7就多了个区间乘. 类似于线段树,由于乘法的优先级高于加法,因此 ...

  8. Luogu P2002 消息扩散&&P1262 间谍网络

    怕自己太久没写Tarjan了就会把这种神仙算法忘掉. 其实这种类型的图论题的套路还是比较简单且显然的. P2002 消息扩散 很显然的题目,因为在一个环(其实就是强连通分量)中的城市都只需要让其中一个 ...

  9. [Oracle][Partition][Controlfile]Partition 操作是否和 Controlfile有关?

    Partition 操作是否和 Controlfile有关? 通过实验来判断: 对比 Partition 前后的操作,看看controlfile 的dump 信息中是否有记录,结果发现没有记录在 co ...

  10. win10系统安装web3js的正确方法(2)

    信渤网络科技是一家基于互联网信息服务的区块链技术公司,专业提供区块链技术培训,智能合约定制开发,文字图片数据存证上链等服务,为相关企业提供区块链应用落地项目的技术方案 崇尚代码即法律,做一个智能合约开 ...