题解

传送门

题解

我是真的不明白这玩意儿是怎么跟反演扯上关系的……

首先

\[\begin{align}
ans
&=b\sum_{d|b}{1\over d}\sum_{i=a}^{b}i[\gcd(i,b)=d]\\
&=b\sum_{d|b}\sum_{i=\lceil{a\over d}\rceil}^{b\over d}i[gcd(i,{b\over d})=1]\\
\end{align}
\]

然后有一个非常神仙的操作……就是强行反演一波,把\([n=1]\)化成\(\sum_{i|n}\mu(i)\)

\[\begin{align}
ans
&=b\sum_{d|b}\sum_{i=\lceil{a\over d}\rceil}^{b\over d}i\sum_{j|\gcd(i,{b\over d})}\mu(j)\\
&=b\sum_{d|b}\sum_{j|{b\over d}}\mu(j)\sum_{i=\lceil{a\over d}\rceil}^{b\over d}[i \mod j=0]\\
&=b\sum_{d|b}\sum_{j|{b\over d}}\mu(j)\sum_{i=\lceil{a\over d}\rceil}^{b\over d}[i \mod j=0]\\
&={b\over 2}\sum_{d|b}\sum_{j|{b\over d}}\mu(j)j(\lfloor{b\over {dj}}\rfloor+\lceil{a\over {dj}}\rceil)(\lfloor{b\over {dj}}\rfloor-\lceil{a\over {dj}}\rceil+1)\\
&={b\over 2}\sum_{T|b}(\lfloor{b\over T}\rfloor+\lceil{a\over T}\rceil)(\lfloor{b\over T}\rfloor-\lceil{a\over T}\rceil+1)\sum_{d|T}\mu(d)d\\
\end{align}
\]

那么我们只要把\(b\)分解一下质因数,然后\(dfs\)找出\(b\)的所有因子就可以了

然而这里还有一个问题,就是\(f(T)=\sum_{d|T}\mu(d)d\)该怎么快速计算

首先我们可以发现\(f\)也是个积性函数,有\(f(p)=1-p,f(p^c)=1-p\)

因为只有次数小于等于\(1\)的质因子会有贡献,所以我们在爆搜枚举因数的时候,如果\(p\nmid i\),那么\(f(i\times p)=f(i)\times(1-p)\)

然后就没有然后了

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R int x){
if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=1e5+5,P=1e9+7,inv2=500000004;
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
R int res=1;
for(;y;y>>=1,x=mul(x,x))if(y&1)res=mul(res,x);
return res;
}
bitset<N>vis;int p[N],v[N],c[N],top,m,sqr,n,tot,res,g;
void init(int n){
fp(i,2,n){
if(!vis[i])p[++tot]=i;
for(R int j=1;j<=tot&&1ll*i*p[j]<=n;++j){
vis[i*p[j]]=1;
if(i%p[j]==0)break;
}
}
}
inline int calc(R int x,R int y){
R int a=n/x,b=(m+x-1)/x;
return 1ll*(a+b)*(a-b+1)%P*y%P;
}
void dfs(int pos,int val,int mu){
if(pos==top+1)return res=add(res,calc(val,mu)),void();
dfs(pos+1,val,mu),mu=mul(mu,dec(1,v[pos]));
fp(i,1,c[pos])val*=v[pos],dfs(pos+1,val,mu);
}
void solve(){
top=0,res=0,g=n;
for(R int i=1;i<=tot&&1ll*p[i]*p[i]<=g;++i)if(g%p[i]==0){
v[++top]=p[i],c[top]=0;
while(g%p[i]==0)g/=p[i],++c[top];
}
if(g!=1)v[++top]=g,c[top]=1;
dfs(1,1,1);
res=1ll*res*n%P*inv2%P;
print(res);
}
int main(){
// freopen("testdata.in","r",stdin);
// freopen("testdata.out","w",stdout);
int T=read();init(sqr=N-5);
while(T--)m=read(),n=read(),solve();
return Ot(),0;
}

[51nod1190]最小公倍数之和V2(莫比乌斯反演)的更多相关文章

  1. 51nod1238 最小公倍数之和 V3(莫比乌斯反演)

    题意 题目链接 Sol 不想打公式了,最后就是求一个 \(\sum_{i=1}^n ig(\frac{N}{i})\) \(g(i) = \sum_{i=1}^n \phi(i) i^2\) 拉个\( ...

  2. 【CJOJ2512】gcd之和(莫比乌斯反演)

    [CJOJ2512]gcd之和(莫比乌斯反演) 题面 给定\(n,m(n,m<=10^7)\) 求 \[\sum_{i=1}^n\sum_{j=1}^mgcd(i,j)\] 题解 首先把公因数直 ...

  3. 51nod 1190 最小公倍数之和 V2

    给出2个数a, b,求LCM(a,b) + LCM(a+1,b) + .. + LCM(b,b). 例如:a = 1, b = 6,1,2,3,4,5,6 同6的最小公倍数分别为6,6,6,12,30 ...

  4. 51nod 1190 最小公倍数之和 V2【莫比乌斯反演】

    参考:http://blog.csdn.net/u014610830/article/details/49493279 这道题做起来感觉非常奇怪啊--头一次见把mu推出来再推没了的-- \[ \sum ...

  5. 51nod1238 最小公倍数之和 V3 莫比乌斯函数 杜教筛

    题意:求\(\sum_{i = 1}^{n}\sum_{j = 1}^{n}lcm(i, j)\). 题解:虽然网上很多题解说用mu卡不过去,,,不过试了一下貌似时间还挺充足的,..也许有时间用phi ...

  6. [51nod1222] 最小公倍数计数(莫比乌斯反演)

    题面 传送门 题解 我此生可能注定要和反演过不去了--死都看不出来为啥它会突然繁衍反演起来啊-- 设\(f(n)=\sum_{i=1}^n\sum_{j=1}^n[{ij\over\gcd(i,j)} ...

  7. 51nod 1222 最小公倍数计数【莫比乌斯反演】

    参考:https://www.cnblogs.com/SilverNebula/p/7045199.html 所是反演其实反演作用不大,又是一道做起来感觉诡异的题 转成前缀和相减的形式 \[ \sum ...

  8. 51Nod.1237.最大公约数之和 V3(莫比乌斯反演 杜教筛 欧拉函数)

    题目链接 \(Description\) \(n\leq 10^{10}\),求 \[\sum_{i=1}^n\sum_{j=1}^ngcd(i,j)\ mod\ (1e9+7)\] \(Soluti ...

  9. 【51Nod 1190】最小公倍数之和 V2

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1190 \[ \begin{aligned} &\sum_{i=a ...

随机推荐

  1. PostgreSQL 9.5 客户端认证

    PostgreSQL 9.5 客户端认证 当一个客户端应用连接一个数据库服务器时,它将指定以哪个PostgreSQL 数据库用户名连接,就像我们以一个特定用户登录一台 Unix 计算机一样.在 SQL ...

  2. Rails的静态资源管理(一)——Asset Pipeline是什么

    官方文档:http://guides.ruby-china.org/asset_pipeline.html http://guides.rubyonrails.org/asset_pipeline.h ...

  3. Task用法(1)-启动方法

    第一.基本使用 Thread,ThreadPool,Task的区别 Task是.NET4.0加入的,跟线程池ThreadPool的功能类似,用Task开启新任务时,会从线程池中调用线程,而Thread ...

  4. 通过phpMyAdmin拿webshell

    general_log默认为关闭的,root权限开启后,general_log_file会保存所有的查询语句 所以可以开启general_log,然后设置general_log_file为一个php文 ...

  5. 11-28 网页基础--JavaScript(DOM)

    网页基础 第二部分--HTMLDOM操作 一.定义:htmlDOM是一种面向对象的树的模型,它包含html中的所有元素:通过html可以找到所有包含在dom中的元素. 二.作用: 1.查找html元素 ...

  6. ConfigureAwait(false)

    昨天在做项目的时候,用的dapper查数据用的QueryAsync 异步方法.给上级做代码审核时,上级说最好加上ConfigureAwait(false).能减少一些性能开销. 因为之前没用过所以看了 ...

  7. pl/sql对excel数据的导入和导出

    本来这部分是在上篇pl/sql的,但笔者介于此篇的内容,就独立出来了, 1.导出查询结果到excel文件,在查询结果上右键,然后弹出选择框如下: 2.从excel向数据库中导入数据: a.创建要导入的 ...

  8. DAY17-Django之logging

    LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'standard': { 'format': ...

  9. Velocity根据模版生成静态html

    新公司的一个CMS项目要用到,这里记录下 一.项目文件图 二.springmvc-servlet.xml 添加 <!-- 定义环境变量文件 --> <bean id="pr ...

  10. maven 配置说明

    1.坐标 1.1 每一jar文件都有一个唯一坐标.通过坐标可以精确确定是哪个jar 1.2 坐标组成 1.2.1 Group ID : 公司名.公司网址倒写 1.2.2 Artifact ID : 项 ...