题意:求$\sum_{i=1}^{n}\sum_{j=1}^{n}d(ij)$

首先推一发式子:

$\sum_{i=1}^{n}\sum_{j=1}^{n}d(ij)$

有一个结论:$d(nm)=\sum_{i|n}\sum_{j|m}[gcd(i,j)\equiv 1]$

然后代入,得:

$\sum_{i=1}^{n}\sum_{j=1}^{n}\sum_{p|i}\sum_{q|j}[gcd(p,q)\equiv 1]$

然后优先枚举$p$,$q$,得到:

$\sum_{p=1}^{n}\sum_{q=1}^{n}[gcd(p,q)\equiv 1]\sum_{p|i}\sum_{q|j}1$

那么也就是:

$\sum_{p=1}^{n}\sum_{q=1}^{n}[gcd(p,q)\equiv 1]\frac{n}{p}\frac{n}{q}$

接下来就是常规步骤了

$\sum_{p=1}^{n}\sum_{q=1}^{n}\sum_{t|gcd(p,q)}\mu(t)\frac{n}{p}\frac{n}{p}$

也就是:

$\sum_{t=1}^{n}\mu(t)\sum_{p=1}^{\frac{n}{t}}\frac{n}{pt}\sum_{q=1}^{\frac{n}{t}}\frac{n}{qt}$

设$f(n)=\sum_{i=1}^{n}\frac{n}{i}$,那么后面就可以变成$\sum_{t=1}^{n}\mu(t)f(\frac{n}{t})^{2}$

求$f$可以数论分块,用杜教筛筛出$\mu$的前缀和之后再套个数论分块即可

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#define ll long long
using namespace std;
const ll mode=1000000007;
map <ll,ll> S;
int mu[10000005];
ll s[10000005];
int pri[10000005];
int cnt=0;
bool used[10000005];
void init()
{
mu[1]=s[1]=1;
for(int i=2;i<=10000000;i++)
{
if(!used[i])pri[++cnt]=i,mu[i]=-1;
for(int j=1;j<=cnt&&i*pri[j]<=10000000;j++)
{
used[i*pri[j]]=1;
if(i%pri[j]==0){mu[i*pri[j]]=0;break;}
mu[i*pri[j]]=-mu[i];
}
s[i]=(s[i-1]+mu[i]+mode)%mode;
}
}
ll get_S(ll x)
{
if(x<=10000000)return s[x];
else if(S.find(x)!=S.end())return S[x];
ll ret=0;
int las=0;
for(int i=2;i<=x;i=las+1)
{
las=x/(x/i);
ll temp=get_S(x/i);
ret=(ret+temp*(las-i+1)+mode)%mode;
}
ret=(1+mode-ret)%mode;
return S[x]=ret;
}
ll get_sum(ll x)
{
ll las=0,ret=0;
for(int i=1;i<=x;i=las+1)
{
las=x/(x/i);
ret+=(las-i+1)*(x/i)%mode;
ret%=mode;
}
return ret*ret%mode;
}
ll solve(ll n)
{
ll las=0,ret=0;
for(int i=1;i<=n;i=las+1)
{
las=n/(n/i);
ret+=(get_S(las)-get_S(i-1)+mode)%mode*get_sum(n/i)%mode;
ret%=mode;
}
return ret;
}
int main()
{
init();
ll n;
scanf("%lld",&n);
printf("%lld\n",solve(n));
return 0;
}

bzoj 4176的更多相关文章

  1. bzoj 4176 Lucas的数论

    bzoj 4176 Lucas的数论 和约数个数和那题差不多.只不过那个题是多组询问,这题只询问一次,并且 \(n\) 开到了 \(10^9\). \[ \begin{align*} \sum_{i= ...

  2. Mobius反演与积性函数前缀和演学习笔记 BZOJ 4176 Lucas的数论 SDOI 2015 约数个数和

    下文中所有讨论都在数论函数范围内开展. 数论函数指的是定义域为正整数域, 且值域为复数域的函数. 数论意义下的和式处理技巧 因子 \[ \sum_{d | n} a_d = \sum_{d | n} ...

  3. ●BZOJ 4176 Lucas的数论

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=4176 题解: 莫比乌斯反演,杜教筛 首先有这么一个结论: 令d(n)表示n的约数的个数(就是 ...

  4. BZOJ 4176: Lucas的数论 [杜教筛]

    4176: Lucas的数论 题意:求\(\sum_{i=1}^n \sum_{j=1}^n \sigma_0(ij)\) \(n \le 10^9\) 代入\(\sigma_0(nm)=\sum_{ ...

  5. 【刷题】BZOJ 4176 Lucas的数论

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

  6. bzoj 4176: Lucas的数论 -- 杜教筛,莫比乌斯反演

    4176: Lucas的数论 Time Limit: 30 Sec  Memory Limit: 256 MB Description 去年的Lucas非常喜欢数论题,但是一年以后的Lucas却不那么 ...

  7. [bzoj 4176] Lucas的数论 (杜教筛 + 莫比乌斯反演)

    题面 设d(x)d(x)d(x)为xxx的约数个数,给定NNN,求 ∑i=1N∑j=1Nd(ij)\sum^{N}_{i=1}\sum^{N}_{j=1} d(ij)i=1∑N​j=1∑N​d(ij) ...

  8. 【bzoj 4176】 Lucas的数论 莫比乌斯反演(杜教筛)

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

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

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

  10. bzoj 4176: Lucas的数论【莫比乌斯反演+杜教筛】

    首先由这样一个结论: \[ d(ij)=\sum_{p|i}\sum_{q|j}[gcd(p,q)==1] \] 然后推反演公式: \[ \sum_{i=1}^{n}\sum_{j=1}^{n}\su ...

随机推荐

  1. 【虚拟机】虚拟机安装win10

    VMware-workstation 16 pro 点击查看代码 密钥: ZF3R0-FHED2-M80TY-8QYGC-NPKYF YF390-0HF8P-M81RQ-2DXQE-M2UT6 ZF7 ...

  2. 剑指 Offer II 树

    我为什么要把代码粘在这里 断更很久了,基于一个错误的观念:我想看题,我到leetcode官网看不就行了吗? 但是若干年后我可能还会到我的博客园看看呀,我有可能上刷题网站吗?而且心得不好写到注释上. 记 ...

  3. 免费赠票 | Cloud Ace 受邀参加 GTC2022 全球流量大会,助力中国企业扬帆出海!

    Cloud Ace 受邀参加 GTC2022 全球流量大会,助力中国企业扬帆出海!   大会将在 2023 年 2 月 28 日-3 月 1 日举行,地点就在福田会展中心 6 号展馆.大会门票实行收费 ...

  4. PS 查看进行状态

    原文:https://blog.csdn.net/lyndon_li/article/details/114295654 ps 查看进行状态有如下几种: ... PROCESS STATE CODES ...

  5. 关于htpasswd

    什么是 htpasswd htpasswd是一个apache的内置工具,其生成的文件称之为htpasswd文件.htpasswd文件本身一个密码本,或者类似于数据库一样,用来存储一些密码(凭证)信息. ...

  6. scrcpy不使用adb远程控制android

    1.开启服务器 CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 1.23 ...

  7. iOS线程 - GCD在开发中的常见问题

    GCD 在开发中的常见问题 1 - 主线程中调用方法 ① 执行 testONE 后的输出结果:1  5  2  4  3 1 -(void)testONE{ 2 3 // 并发队列 4 dispatc ...

  8. OC基础 - isMemberOfClass | isKindOfClass

    isMemberOfClass | isKindOfClass 1 - 猜想以下代码输出的结果 1 #import <Foundation/Foundation.h> 2 #import ...

  9. 【python】读写文件

    1.打开文件与文件模式 1.1 文件模式 (1) 'r':读取模式(默认文件模式,显式指定读取模式的效果和不指定模式相同); (2) 'w':写入模式(如果写入时,文件不存在,会创建文件); 注1:其 ...

  10. h5py学习(一)核心概念

    因pandas的to_hdf5函数有bug TypeError: object of type 'int' has no len(),写dataframe数据出现了报错,遂决定直接使用h5py来写数据 ...