大意: 给定$n,m$, 求$\sum\limits_{i=1}^n\sum\limits_{j=1}^m\mu(lcm(i,j))$

首先有$\mu(lcm(i,j))=\mu(i)\mu(j)\mu(gcd(i,j))$

枚举$gcd$可以得到$\sum\limits_{d=1}^{min(n,m)}\mu(d)\sum\limits_{i=1}^{\lfloor\frac{n}{d}\rfloor}\sum\limits_{j=1}^{\lfloor\frac{m}{d}\rfloor}\mu(id)\mu(jd)[gcd(i,j)=1]$

再反演一下就有$\sum\limits_{d_1=1}^{min(n,m)}\mu(d_1)\sum\limits_{d_2=1}^{\lfloor\frac{min(n,m)}{d_1}\rfloor}\mu(d_2)\sum\limits_{i=1}^{\lfloor\frac{n}{d_1d_2}\rfloor}\sum\limits_{j=1}^{\lfloor\frac{m}{d_1d_2}\rfloor}\mu(id_1d_2)\mu(jd_1d_2)$

枚举$d_1d_2$就有$\sum\limits_{T=1}^{min(n,m)}\sum\limits_{d\mid T}\mu(d)\mu(\frac{T}{d})\sum\limits_{i=1}^{\lfloor\frac{n}{T}\rfloor}\mu(iT)\sum\limits_{j=1}^{\lfloor\frac{m}{T}\rfloor}\mu(jT)$

预处理一下$\mu * \mu$即可

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 1e6+50;
int cnt, p[N], mu[N], mu2[N], vis[N]; void init() {
mu[1] = mu2[1] = 1;
REP(i,2,N-1) {
if (!vis[i]) p[++cnt]=i,mu[i]=-1,mu2[i]=-2;
for (int j=1,t; j<=cnt&&i*p[j]<N; ++j) {
vis[t=i*p[j]] = 1;
if (i%p[j]==0) {
mu[t] = 0;
if (i/p[j]%p[j]==0) mu2[t] = 0;
else mu2[t] = 1;
break;
}
mu[t] = -mu[i];
mu2[t] = -2*mu2[i];
}
}
} void work() {
int n, m;
scanf("%d%d", &n, &m);
int mx = min(n,m), ans = 0;
REP(i,1,mx) {
int r1 = 0, r2 = 0;
for (int j=i; j<=n; j+=i) r1+=mu[j];
for (int j=i; j<=m; j+=i) r2+=mu[j];
ans += mu2[i]*r1*r2;
}
printf("%d\n", ans);
} int main() {
init();
int t;
scanf("%d", &t);
while (t--) work();
}

算术 HDU - 6715 (莫比乌斯反演)的更多相关文章

  1. HDU 4746 (莫比乌斯反演) Mophues

    这道题看巨巨的题解看了好久,好久.. 本文转自hdu4746(莫比乌斯反演) 题意:给出n, m, p,求有多少对a, b满足gcd(a, b)的素因子个数<=p,(其中1<=a<= ...

  2. HDU 1695 (莫比乌斯反演) GCD

    题意: 从区间[1, b]和[1, d]中分别选一个x, y,使得gcd(x, y) = k, 求满足条件的xy的对数(不区分xy的顺序) 分析: 虽然之前写过一个莫比乌斯反演的总结,可遇到这道题还是 ...

  3. GCD HDU - 1695 莫比乌斯反演入门

    题目链接:https://cn.vjudge.net/problem/HDU-1695#author=541607120101 感觉讲的很好的一个博客:https://www.cnblogs.com/ ...

  4. HDU 5212 莫比乌斯反演

    Code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  5. hdu 1695(莫比乌斯反演)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  6. HDU 6053(莫比乌斯反演)

    题意略. 思路:首先想到暴力去扫,这样的复杂度是n * min(ai),对于gcd = p,对答案的贡献应该是 (a1 / p) * (a2 / p) * .... * (an / p),得出这个贡献 ...

  7. hdu 4746Mophues[莫比乌斯反演]

    Mophues Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327670/327670 K (Java/Others) Total ...

  8. HDU 4746 莫比乌斯反演+离线查询+树状数组

    题目大意: 一个数字组成一堆素因子的乘积,如果一个数字的素因子个数(同样的素因子也要多次计数)小于等于P,那么就称这个数是P的幸运数 多次询问1<=x<=n,1<=y<=m,P ...

  9. HDU 5382 莫比乌斯反演

    题目大意: 求S(n)的值 n<=1000000 这是官方题解给出的推导过程,orz,按这上面说的来写,就不难了 这里需要思考的就是G(n)这个如何利用积性函数的性质线性筛出来 作为一个质数,那 ...

随机推荐

  1. Java-Maven(十):Maven 项目常用plugins

    本文主要总结最近一段时间使用maven时,遇到需要maven plugins的一些简单总结. 1)在Build下重新指定最终打包报名 <build> <!--最终打包的包名,如果这里 ...

  2. Java hashCode与equals学习

    1.关于Object类的equals方法的特点 a) 自反性: x.equals(x) 应该返回true b) 对称性: x.equals(y)为true,那么y.equals(x) 也为true c ...

  3. gcov—a Test Coverage Program

    gcov—a Test Coverage Program https://coverage.readthedocs.io/en/v4.5.x/cmd.html 覆盖率测试

  4. C#随机挑选某一个用户或者几个用户信息

    && u.EnabledMark == ).OrderBy(_=>Guid.NewGuid()).Take(); && u.EnabledMark == ).Or ...

  5. 006 GET API

    1.说明 The get API allows to get a JSON document from the index based on its id. GET通过基于id的索引获取JSON文档. ...

  6. Python3基础 内置函数 hash

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...

  7. wpf程序,只允许运行一个程序实例问题

    https://bbs.csdn.net/topics/390486402 https://codereview.stackexchange.com/questions/20871/single-in ...

  8. xcopy命令拷贝文件夹和文件

    文件夹: xcopy /r /y 'c:123\' 'D:\123\' 文件: echo f | xcopy  /d /r /k  c:\index2.htm c:\index.htm

  9. 泡泡一分钟:Visual Odometry Using a Homography Formulation with Decoupled Rotation and Translation Estimation Using Minimal Solutions

    张宁 Visual Odometry Using a Homography Formulation with Decoupled Rotation and Translation Estimation ...

  10. Linux记录-Nginx+Tomcat负载均衡配置

    Nginx负载均衡配置及策略: 轮询(默认) 优点:实现简单缺点:不考虑每台服务器的处理能力配置示例如下:upstream www.xxx.com {# 需要负载的server列表server www ...