传送门

题目所给的不合法的条件可以转化为

\[\exists p,p^2|gcd(a,b) \Leftrightarrow \mu(gcd(a,b))\ne 0
\]

那么

\[ans=\sum_{a=1}^{A}\sum_{b=1}^{B}[\mu(gcd(i,j))\ne 0]\frac{ab}{gcd(a,b)}
\]

不妨假设 \(A\le B\),枚举 \(gcd\) 之后经典莫比乌斯反演

设 \(S(x)=\sum_{i=1}^{x}i\)

得到

\[\sum_{i=1}^{A}S(\lfloor\frac{A}{i}\rfloor)S(\lfloor\frac{B}{i}\rfloor)\sum_{d|i}[\mu(d)\ne 0](\frac{i}{d})^2\mu(\frac{i}{d})d
\]

后面的狄利克雷卷积是一个积性函数,直接线性筛

# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint; const int maxn(4e6 + 5);
const int mod(1 << 30); int test, pr[maxn], tot, n, m, cnt[maxn], pwd[maxn];
uint ans, s[maxn];
bitset <maxn> ispr; inline uint S(uint x) {
return (x & 1) ? (x + 1) / 2 * x : x / 2 * (x + 1);
} int main() {
register uint i, j;
ispr[1] = 1, s[1] = 1;
for (i = 2; i < maxn; ++i) {
if (!ispr[i]) pwd[i] = pr[++tot] = i, s[i] = i - i * i, cnt[i] = 1;
for (j = 1; j <= tot && i * pr[j] < maxn; ++j) {
ispr[i * pr[j]] = 1;
if (i % pr[j]) {
s[i * pr[j]] = s[i] * s[pr[j]];
pwd[i * pr[j]] = pr[j], cnt[i * pr[j]] = 1;
}
else {
cnt[i * pr[j]] = cnt[i] + 1, pwd[i * pr[j]] = pwd[i] * pr[j];
if (cnt[i] == 1) s[i * pr[j]] = -(uint)pr[j] * pr[j] * pr[j] * s[i / pwd[i]];
else s[i * pr[j]] = 0;
break;
}
}
}
for (i = 2; i < maxn; ++i) s[i] += s[i - 1];
scanf("%d", &test);
while (test) {
scanf("%d%d", &n, &m), test--;
if (n > m) swap(n, m);
for (ans = 0, i = 1; i <= n; i = j + 1) {
j = min(n / (n / i), m / (m / i));
ans += (s[j] - s[i - 1]) * S(n / i) * S(m / i);
}
printf("%u\n", ans % mod);
}
return 0;
}

BZOJ4659:lcm的更多相关文章

  1. MTK Android Driver :Lcm

    MTK Android Driver :lcm 1.怎样新建一个LCD驱动 LCD模组主要包括LCD显示屏和驱动IC.比如LF040DNYB16a模组的驱动IC型号为NT35510.要在MTK6577 ...

  2. BZOJ2694:Lcm——包看得懂/看不懂题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=2694 Description 对于任意的>1的n gcd(a, b)不是n^2的倍数 也就是说 ...

  3. [洛谷P5106]dkw的lcm:欧拉函数+容斥原理+扩展欧拉定理

    分析 考虑使用欧拉函数的计算公式化简原式,因为有: \[lcm(i_1,i_2,...,i_k)=p_1^{q_{1\ max}} \times p_2^{q_{2\ max}} \times ... ...

  4. LCM性质 + 组合数 - HDU 5407 CRB and Candies

    CRB and Candies Problem's Link Mean: 给定一个数n,求LCM(C(n,0),C(n,1),C(n,2)...C(n,n))的值,(n<=1e6). analy ...

  5. LCM在Kernel中的代码分析

    lcm的分析首先是mtkfb.c 1.mtk_init中platform_driver_register(&mtkfb_driver)注册平台驱动 panelmaster_init(); DB ...

  6. LightOj 1236 - Pairs Forming LCM (分解素因子,LCM )

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意:给你一个数n,求有多少对(i,  j)满足 LCM(i, j) = n, ...

  7. LOJ Finding LCM(math)

    1215 - Finding LCM Time Limit: 2 second(s) Memory Limit: 32 MB LCM is an abbreviation used for Least ...

  8. POJ 2429 GCD & LCM Inverse (Pollard rho整数分解+dfs枚举)

    题意:给出a和b的gcd和lcm,让你求a和b.按升序输出a和b.若有多组满足条件的a和b,那么输出a+b最小的.思路:lcm=a*b/gcd   lcm/gcd=a/gcd*b/gcd 可知a/gc ...

  9. mtk lcm驱动加载流程 (转载)

    平台:mt6582 + Android 4.4 前面就说过,在mtk代码中支持屏是可兼容的,通过调用驱动中的compare_id函数来匹配驱动和屏,这里来细看一下代码. 1. LK部分(mediate ...

随机推荐

  1. python os用法详解

    前言:在自动化测试中,经常需要查找操作文件,比如说查找配置文件(从而读取配置文件的信息),查找测试报告(从而发送测试报告邮件),经常要对大量文件和大量路径进行操作,这就依赖于os模块,所以今天整理下比 ...

  2. oracle常用cmd命令

    登陆 sqlplus username/password; 切换: conn username/password; 显示当前登陆用户: show user; 查看用户列表 select usernam ...

  3. Mysql 四种事务隔离介绍以及锁机制

    还有很多不太懂,这里收集几份大佬文章“飞机票”,待我整理好了,再好好写一篇文章吧. MySQL的四种事务隔离级别 https://www.cnblogs.com/huanongying/p/70215 ...

  4. spark中资源调度任务调度

    在spark的资源调度中 1.集群启动worker向master汇报资源情况 2.Client向集群提交app,向master注册一个driver(需要多少core.memery),启动一个drive ...

  5. php 前台生成多维数组 后台批量添加

    同一个地方绊倒两次,记录一下哈 1)前台表单,看 name <div class="tab-pane row " id="tab-1" > < ...

  6. Altium Designer安装孔周围放置圆形Polygon Pour Cutout

    1.  在Keep-Out层画2个圆, 中间的圆用作安装孔, 外圆做为禁止覆铜层. 这样做的好处是,放好安装孔后, 外面禁止覆铜层也覆不上铜, 防止螺钉与覆铜接触. 2. 选中外圆, Tools -& ...

  7. 用Python写了一个postgresql函数,感觉很爽

    用Python写了一个postgresql函数,感觉很爽 CREATE LANGUAGE plpythonu; postgresql函数 CREATE OR REPLACE FUNCTION myfu ...

  8. Android开发最佳实践

    Android开发最佳实践 摘要 ●使用 Gradle 和它推荐的工程结构 ●把密码和敏感数据放在gradle.properties ●不要自己写 HTTP 客户端,使用Volley或OkHttp库 ...

  9. springboot项目:登录 登录aop拦截 使用Redis与cookie 进行设置获取清除操作

    登录.登出: 第一步:在pom文件中引入依赖 <dependency> <groupId>org.springframework.boot</groupId> &l ...

  10. Windows Git Bash命令行下创建git仓库并更新到github

    大二的时候就听过老师说有一个叫git的版本管理工具,当时只是听老师说说而已,也没有去使用它,因为当时用过svn,就感觉自己没多少东西需要git管理. 最近几天,我经常在开源中国看别人的帖子,看到别人对 ...