题意

求 $$\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. C#的delegate简单练习

    delegate中文的意思为委托. 在很久之前,Insus.NET有写过一篇<用一个简单的例子来演绎事件委托>http://www.cnblogs.com/insus/p/3732075. ...

  2. 微信小程序案例:获取微信访问用户的openid

    在微信开发项目中,获取openid是项目常遇的问题,本文通过主要讲解实现在微信小程序中如何获取用户的openid,案例实现非常简单 具体实现方法是通过登录接口获取登录凭证,然后通过request请求微 ...

  3. Codeforces 996E Leaving the Bar (随机化)

    题目连接:Leaving the Bar 题意:给你n个向量,你可以加这个向量或减这个向量,使得这些向量之和的长度小于1.5e6. 题解: 按照正常的贪心方法,最后的结果有可能大于1.5e6 .这里我 ...

  4. 关于node.js的进程管理

    如果是单纯的运行一个node进程,那会比较简单,例如: node ./example.js 但是一般来说,当我们运行一个node进程之后,我们可能希望对这个进程进行更多的管理,例如,当node程序是一 ...

  5. 案例学python——案例二:连接数据库MySql

    调侃的话:案例一跑完之后,欣赏把玩了一番.人就有点飘飘然,昨天除了做饭吃饭,就是玩三国杀,江郎才尽,今天周一,不飘了,敲点代码,看看Python操作数据库有啥不一样的. 前期准备: 1.数据库 电脑上 ...

  6. 认识Python&基础环境搭建

    前言 作为.NET Coder可能.NET Core是现阶段首要学习方向,但是说实在的对Core真的不感冒. 原因有几点: 1.公司项目底层需要的一部分库,Core还不支持. 2.同样的需求,.NET ...

  7. [Entity Framework+MVC复习总结1]-WebForm与Asp.Net MVC

    一.Web开发方式的比较 二.web Form开发模型 WebForm开发优点: 1.支持事件模型开发.得益于丰富的服务器端组件,webfrom开发可以迅速的搭建web应用 2.使用方便,入门容易 3 ...

  8. .NET Standard库引用导致的FileNotFoundException探究

    微软近几年推出.NET Standard,将.NET Framework,.NET Core,Xamarin等目标平台的api进行标准化和统一化,极大地方便了类库编写人员的工作.简单的说,类库编写人员 ...

  9. 【Beta阶段】M2事后分析

    先上照片,最后一次开会了啊... 计划 你原计划的工作是否最后都做完了? 如果有没做完的,为什么? 答:没有全部做完,到目前为止,我们的还有几个实验的报告生成功能没有上线.这几个实验的数据处理文件已经 ...

  10. SpringBoot-简单实例

    在进行实例之前,首先须确保电脑环境变量已经配置好,包括jdk.maven.此文章不做描述,不清楚自行百度. 第一步:来到springboot官网(https://start.spring.io/)下载 ...