BZOJ4659:lcm
传送门
题目所给的不合法的条件可以转化为
\]
那么
\]
不妨假设 \(A\le B\),枚举 \(gcd\) 之后经典莫比乌斯反演
设 \(S(x)=\sum_{i=1}^{x}i\)
得到
\]
后面的狄利克雷卷积是一个积性函数,直接线性筛
# 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的更多相关文章
- MTK Android Driver :Lcm
MTK Android Driver :lcm 1.怎样新建一个LCD驱动 LCD模组主要包括LCD显示屏和驱动IC.比如LF040DNYB16a模组的驱动IC型号为NT35510.要在MTK6577 ...
- BZOJ2694:Lcm——包看得懂/看不懂题解
http://www.lydsy.com/JudgeOnline/problem.php?id=2694 Description 对于任意的>1的n gcd(a, b)不是n^2的倍数 也就是说 ...
- [洛谷P5106]dkw的lcm:欧拉函数+容斥原理+扩展欧拉定理
分析 考虑使用欧拉函数的计算公式化简原式,因为有: \[lcm(i_1,i_2,...,i_k)=p_1^{q_{1\ max}} \times p_2^{q_{2\ max}} \times ... ...
- 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 ...
- LCM在Kernel中的代码分析
lcm的分析首先是mtkfb.c 1.mtk_init中platform_driver_register(&mtkfb_driver)注册平台驱动 panelmaster_init(); DB ...
- LightOj 1236 - Pairs Forming LCM (分解素因子,LCM )
题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意:给你一个数n,求有多少对(i, j)满足 LCM(i, j) = n, ...
- LOJ Finding LCM(math)
1215 - Finding LCM Time Limit: 2 second(s) Memory Limit: 32 MB LCM is an abbreviation used for Least ...
- 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 ...
- mtk lcm驱动加载流程 (转载)
平台:mt6582 + Android 4.4 前面就说过,在mtk代码中支持屏是可兼容的,通过调用驱动中的compare_id函数来匹配驱动和屏,这里来细看一下代码. 1. LK部分(mediate ...
随机推荐
- HTML实例(四)
实例一:有序列表,无序列表,<dl>,<dt>,<dd>,div块级标签等,实现上面的效果. <!DOCTYPE html> <html lang ...
- Github 升级到 Rails 5.2.1 了
简评:之前用的可是 3.2,早就该升级了啊. Github 的 Rails 升级花了大约一年半的时间,这是有原因的,首先,Rails 本身的升级并不总是平滑的,有些版本有重大改变(breaking c ...
- JavaScript变量那些事
引言 JavaScript的变量本质是松散类型的,也就是说其变量就是用于保存特定值的一个名字,变量的值和数据类型可以在脚本执行的生命周期中发生变化.这是一个很有趣很强大的特性,但是也是一个极容易出错误 ...
- P4859 已经没有什么好害怕的了
传送门 见计数想容斥 首先题目可以简单转化一下, 求 糖果比药片能量大的组数比药片比糖果能量大的组数多 $k$ 组 的方案数 因为所有能量各不相同,所以就相当于求 糖果比药片能量大的组数为 $(n+k ...
- ElasticSearch 问题分析:No data nodes with HTTP-enabled available
环境:ES-5.4.0版本,部署方式:3master node+2client node+3data node 说明:data node和client node都配置了http.enabled: fa ...
- IE8下不识别indexOf的问题
1.为Array原型添加indexOf方法(如果学过面向对象,相当于给Array类添加实例方法),方法体如下: //添加数组IndexOf方法 if (!Array.prototype.indexOf ...
- 再谈Hive元数据如hive_metadata与Linux里MySQL的深入区别(图文详解)
不多说,直接上干货! [bigdata@s201 conf]$ vim hive-site.xml [bigdata@s201 conf]$ pwd /soft/hive/conf [bigdata@ ...
- 弗格森&红魔
本周日曼联对阵斯旺西时,一位名叫皮特-莫利纽克斯的58岁老人,将会举起一张老旧的床单,就如他曾做过的那样.那一次“臭名昭着”的行为要追溯到1989年12月,弗格森当时已经来到了悬崖边上,他的背后是一堵 ...
- Go RabbitMQ(五)主题
RabbitMQ topic 在之前我们将交换器的类型从fanout设置为direct后能够根据我们的选择获得响应的消息,虽然改良我们的消息日志系统,但是还有很多局限性,比如它不能基于多个标准进行路由 ...
- Digitale Logik
1.Zahl System und Code System 1.1 Die Rechnung des Ergänzungscode 1.2 Manche häufig verwendet Code 1 ...