题意:求\(\sum_{i=1}^n\sum_{j=1}^nd(ij),d是约数个数函数\)

题解:首先有一个结论\(d(ij)=\sum_{x|i}\sum_{y|j}[(i,j)==1]\)

那么\(\sum_{i=1}^n\sum_{j=1}^n\sum_{x|i}\sum_{y|j}\sum_{d|(i,j)}\mu(d)\)

枚举d,\(\sum_{i=1}^n\sum_{j=1}^n\sum_{d|i,d|j}\mu(d)d(\frac{i}{d})d(\frac{j}{d})=\sum_{d=1}^n\mu(d)\sum_{d|i}\sum_{d|j}d(\frac{i}{d})d(\frac{j}{d})=\sum_{d=1}^n\mu(d)\sum_{i=1}^{\lfloor \frac{n}{d} \rfloor}d(i)\sum_{j=1}^{\lfloor \frac{n}{d} \rfloor}d(j)\)

这里我们需要分块求\(\mu\)和\(d\)的前缀和,\(\mu\)很好求,对于d,我们考虑\(d=I*I\),考虑把杜教筛中的\(g(x)=\mu\),\(I*I*\mu=I*e=e\),那么\(S(n)=\sum_{i=1}^n1-\sum_{d=2}\mu(d)S(\lfloor \frac{n}{d} \rfloor)\)

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
//#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
template<typename T>
inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>
inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=5000000+10,maxn=3000000+10,inf=0x3f3f3f3f; int prime[N],cnt;
ll d[N],num[N],mu[N];
bool mark[N];
map<ll,ll>dd,muu;
void init()
{
mu[1]=d[1]=1;
for(int i=2;i<N;i++)
{
if(!mark[i])prime[++cnt]=i,mu[i]=-1,d[i]=2,num[i]=1;
for(int j=1;j<=cnt&&i*prime[j]<N;j++)
{
mark[i*prime[j]]=1;
if(i%prime[j]==0)
{
mu[i*prime[j]]=0;
num[i*prime[j]]=num[i]+1;
d[i*prime[j]]=d[i]/num[i*prime[j]]*(num[i*prime[j]]+1);
break;
}
mu[i*prime[j]]=-mu[i];
d[i*prime[j]]=d[i]<<1;
num[i*prime[j]]=1;
}
}
for(ll i=1;i<N;i++)
{
add(d[i],d[i-1]);
mu[i]=(mu[i]+mod)%mod;
add(mu[i],mu[i-1]);
}
}
ll getmu(ll n)
{
if(n<N)return mu[n];
if(muu.find(n)!=muu.end())return muu[n];
ll ans=1;
for(ll i=2,j;i<=n;i=j+1)
{
j=n/(n/i);
ll te=(j-i+1)%mod;
sub(ans,te*getmu(n/i)%mod);
}
return muu[n]=ans;
}
ll getd(ll n)
{
if(n<N)return d[n];
if(dd.find(n)!=dd.end())return dd[n];
ll ans=n%mod;
for(ll i=2,j;i<=n;i=j+1)
{
j=n/(n/i);
ll te=(getmu(j)-getmu(i-1)+mod)%mod;
sub(ans,te*getd(n/i)%mod);
}
return dd[n]=ans;
}
int main()
{
init();
ll n;scanf("%lld",&n);
ll ans=0;
for(ll i=1,j;i<=n;i=j+1)
{
j=n/(n/i);
ll te=(getmu(j)-getmu(i-1)+mod)%mod;
add(ans,te*getd(n/i)%mod*getd(n/i)%mod);
}
printf("%lld\n",ans);
return 0;
}
/******************** ********************/

bzoj4176. Lucas的数论 杜教筛的更多相关文章

  1. 【BZOJ4176】Lucas的数论-杜教筛

    求$$\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{n}f(ij)$$,其中$f(x)$表示$x$的约数个数,$0\leq n\leq 10^9$,答案膜$10^9+ ...

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

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

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

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

  4. [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) ...

  5. 【XSY2731】Div 数论 杜教筛 莫比乌斯反演

    题目大意 定义复数\(a+bi\)为整数\(k\)的约数,当且仅当\(a\)和\(b\)为整数且存在整数\(c\)和\(d\)满足\((a+bi)(c+di)=k\). 定义复数\(a+bi\)的实部 ...

  6. BZOJ3944 Sum 数论 杜教筛

    原文链接http://www.cnblogs.com/zhouzhendong/p/8671759.html 题目传送门 - BZOJ3944 题意 多组数据(组数<=10). 每组数据一个正整 ...

  7. UOJ#221. 【NOI2016】循环之美 数论,杜教筛

    原文链接www.cnblogs.com/zhouzhendong/p/UOJ221.html 题解 首先把题目转化为求 \[\sum_{x=1}^n \sum_{y=1}^m [\gcd(x,y) = ...

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

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

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

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

随机推荐

  1. 【Hadoop 分布式部署 十:配置HDFS 的HA、启动HA中的各个守护进程】

    官方参考 配置 地址  :http://hadoop.apache.org/docs/r2.5.2/hadoop-project-dist/hadoop-hdfs/HDFSHighAvailabili ...

  2. Thread类的常用方法

    String getName() 返回该线程的名称. void setName(String name) 改变线程名称,使之与参数 name 相同. int getPriority() 返回线程的优先 ...

  3. DAG最小路径点覆盖

    Problem 给出一个有向无环图 (\(DAG\)),求出最少使用其中多少条互不相交的路径覆盖所有点. Solution 若有 \(n\) 个点,对于每个点 \(i\) ,我们将它拆成两个点 \(i ...

  4. 【译】第22节---Fluent API - EntityTypeConfiguration类

    原文:http://www.entityframeworktutorial.net/code-first/entitytypeconfiguration-class.aspx 在我们开始使用Fluen ...

  5. Leetcode121-Best Time to Buy and Sell Stock I - Easy

    I Say you have an array for which the ith element is the price of a given stock on day i. If you wer ...

  6. python实现八皇后问题

    import random def judge(state, nextX): #判断是否和之前的皇后状态有冲突 nextY = len(state) for i in range(nextY): if ...

  7. 转一个集成速锐的ss 回头试试 补充加速一、Vultr安装锐速

    https://liyuans.com/archives/ssr-serverspeeder-onekey.html Debian/Ubuntu 系统 ShadowsocksR 一键安装脚本 (集成锐 ...

  8. Sqlserver中分页,2012后支持offset + fetch,2012之前用rownum嵌套查询

    今天发现原先用的sql offset fetch好用,换了一个DB就歇菜 歇菜截图 比较了一下,是数据库版本的问题 一个是13,一个是10 版本低的不支持用offset + fetch 进行分页,ms ...

  9. webbench高并发测试

    安装ctags sudo apt-get install ctags 安装webbench 下载webbench http://home.tiscali.cz/~cz210552/distfiles/ ...

  10. 使用openpyxl实现excel文件的读取操作

    1.环境准备 python3环境.安装openpyxl模块 2.excel文件数据准备 3.为方便直接调用,本代码直接封装成类 from openpyxl import load_workbook c ...