题意

求 $$\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. React-JSX简介

    JSX 本身其实也是一种表达式 在编译之后呢,JSX 其实会被转化为普通的 JavaScript 对象.这也就意味着,你其实可以在 if 或者 for 语句里使用 JSX,将它赋值给变量,当作参数传入 ...

  2. 大数据之Flume

    什么是Flume ApacheFlume是一个分布式的.可靠的.可用的系统,用于高效地收集.聚合和将大量来自不同来源的日志数据移动到一个集中的数据存储区. 系统要求 1. JDK 1.8 或以上版本 ...

  3. Helper

    //检测端口是否使用 public static bool VerifyListenerPort(int port) { bool inUse = false; System.Net.NetworkI ...

  4. mysql操作命令梳理(5)-执行sql语句查询即mysql状态说明

    在日常mysql运维中,经常要查询当前mysql下正在执行的sql语句及其他在跑的mysql相关线程,这就用到mysql processlist这个命令了.mysql> show process ...

  5. php安全配置记录和常见错误梳理

    通常部署完php环境后会进行一些安全设置,除了熟悉各种php漏洞外,还可以通过配置php.ini来加固PHP的运行环境,PHP官方也曾经多次修改php.ini的默认设置.下面对php.ini中一些安全 ...

  6. 【课程总结】Linux内核分析课程总结

    程涵  原创博客 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 每周实验报告: 反汇编一个简单的C程序 ...

  7. 《Linux内核分析》chapter4

  8. <<梦断代码>>阅读笔记三

    看完了这最后三分之一的<梦断代码>,意味着这本软件行业的著作已经被我粗略地过了一遍. 在这最后三分之一的内容中,我深入了解了在大型软件项目的运作过程中存在的困难和艰辛.一个大型软件项目的成 ...

  9. personal project

    words count program 统计文本文件的字符数,单词数和行数. 实现一个统计程序,他能正确的统计程序文件中的字符数,单词数和行数. 源码链接 https://github.com/sup ...

  10. spring mvc的工作原理

    该文转载自:http://blog.csdn.net/u012191627/article/details/41943393 SpringMVC框架介绍 1) spring MVC属于SpringFr ...