最裸的莫比乌斯

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = 1e5 + ;
const int M = 1e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +; int p[N], is[N], mbs[N], sum[N], n, m, d, ans, tot; void init(){
memset(is, ,sizeof(is));
mbs[]=;
for(int i = ; i < N; i++) {
if(is[i]){
p[++tot] = i;
mbs[i] = -;
}
for(int j = ; j <= tot && p[j] * i < N; j++){
is[i * p[j]] = ;
if(i % p[j] == ){
mbs[i * p[j]] = ;
break;
} else {
mbs[i * p[j]] = -mbs[i];
}
}
}
for(int i = ; i < N; i++) {
sum[i] = mbs[i] + sum[i - ]; //维护前缀和
}
} int cal(int n, int m){ //求[1,n][1,m]区间内互质的(x, y)的对数
int ans=;
if(n > m) swap(n, m);
for(int L = , R=; L <= n; L = R + ) {
R = min(n / (n / L), m /(m / L)); // 分段加速
ans += (sum[R] - sum[L - ]) * (n / L) * (m / L);
}
return ans;
} int main(){
init();
int T; scanf("%d", &T);
while(T--) {
scanf("%d%d%d",&n,&m,&d);
ans = cal(n / d, m / d);
printf("%d\n", ans);
}
return ;
}
/*
*/

bzoj 1101 莫比乌斯反演的更多相关文章

  1. 【题解】Crash的数字表格 BZOJ 2154 莫比乌斯反演

    题目传送门 http://www.lydsy.com/JudgeOnline/problem.php?id=2154 人生中第一道自己做出来的莫比乌斯反演 人生中第一篇用LaTeX写数学公式的博客 大 ...

  2. BZOJ 3309 莫比乌斯反演

    题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=3309 题意:定义f(n)为n所含质因子的最大幂指数,求 $Ans=\sum _{i=1} ...

  3. BZOJ 2301 莫比乌斯反演入门

    2301: [HAOI2011]Problem b Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函 ...

  4. bzoj 2154 莫比乌斯反演求lcm的和

    题目大意: 表格中每一个位置(i,j)填的值是lcm(i,j) , 求n*m的表格值有多大 论文贾志鹏线性筛中过程讲的很好 最后的逆元我利用的是欧拉定理求解的 我这个最后线性扫了一遍,勉强过了,效率不 ...

  5. bzoj 2301 莫比乌斯反演

    对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. 这里题目意思很明显 对于要求的f[n] = sig ...

  6. BZOJ 1101 莫比乌斯函数+分块

    思路: 题目中的gcd(x,y)=d (x<=a,y<=b)可以转化成 求:gcd(x,y)=1 (1<=x<=a/d 1<=y<=b/d) 设 G(x,y)表示x ...

  7. bzoj 2820 莫比乌斯反演

    搞了一整个晚自习,只是看懂了dalao们的博客,目前感觉没有思路-.还是要多切题 next day: 刚才又推了一遍,发现顺过来了,hahaha #include<cstdio> #inc ...

  8. BZOJ - 2818 莫比乌斯反演 初步

    要使用分块的技巧 #include<iostream> #include<algorithm> #include<cstdio> #include<cstri ...

  9. bzoj 2671 莫比乌斯反演

    Calc Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 451  Solved: 234[Submit][Status][Discuss] Descr ...

随机推荐

  1. codeforces 55D 数位dp

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  2. JS中encodeURI、encodeURIComponent、decodeURI、decodeURIComponent

    js 对文字进行编码涉及2个函数:encodeURI,encodeURIComponent,相应2个解码函数:decodeURI,decodeURIComponent 1.用来编码和解码URI的 统一 ...

  3. 海思HI35XX之----视频处理单元各通道间的关系

    最近在折腾HI3518C的芯片,应用到IPCamera上,最终获取多路不同分辨率的视频流供不同需求的预览切换.此处简单记录一下视频前处理元VPSS(Video Process Sub-System)的 ...

  4. UVA 818 Cutting Chains

    https://vjudge.net/problem/UVA-818 题意: 有n个圆环,其中有一些已经扣在了一起.现在需要打开尽量少的圆环,使得所有圆环可以组成一条链 n<=15 因为n< ...

  5. 计算方法 -- 解线性方程组直接法(LU分解、列主元高斯消元、追赶法)

    #include <iostream> #include <cstdio> #include <algorithm> #include <cstdlib> ...

  6. 贪心+离散化+线段树上二分。。。 Samara University ACM ICPC 2016-2017 Quarterfinal Qualification Contest G. Of Zorcs and Axes

    题目链接:http://codeforces.com/gym/101149/problem/G 题目大意:给你n对数字,为(a[i], b[i]),给你m对数字,为(w[i], c[i]).给n对数字 ...

  7. [Luogu 2486] SDOI2011 染色

    [Luogu 2486] SDOI2011 染色 树剖水题,线段树维护. 详细题解不写了. 我只想说我写的线段树又变漂亮了qwq #include <algorithm> #include ...

  8. Why are Eight Bits Enough for Deep Neural Networks?

    Why are Eight Bits Enough for Deep Neural Networks? Deep learning is a very weird technology. It evo ...

  9. HashSet的特性介绍

    HashSet除了在元素的存储上是无序的以外,还是不能够存储重复的元素. HashSet如何判断元素是否重复呢?是根据元素继承的两个方法来判断,hashCode和equals,当存储元素时,首先判断要 ...

  10. TreeMap put 操作分析

    public V put(K key, V value) { //t 表示当前节点,记住这个很重要!先把TreeMap 的根节点root 的引用赋值给当前节点 TreeMap.Entry<K,V ...