最裸的莫比乌斯

#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. (转)C++常见问题: 字符串分割函数 split

    http://www.cnblogs.com/dfcao/p/cpp-FAQ-split.html C++标准库里面没有字符分割函数split ,这可太不方便了,我已经遇到>3次如何对字符串快速 ...

  2. Dubbo 的应用

    ---  用于大规模服务化,通过在消费方获取服务提供方的地址列表,实现负载均衡,减轻服务器压力. 最简单调用图 节点角色说明: l  Provider: 暴露服务的服务提供方. l  Consumer ...

  3. 多例模式,保证实例的唯一性,仅适用于form窗体

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  4. 查询timestamp类型数据

    $where=" roleid = 8 and lizhi = 0 and branchid IN (".implode(",",$ids).") a ...

  5. C.Fountains(Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)+线段树+RMQ)

    题目链接:http://codeforces.com/contest/799/problem/C 题目: 题意: 给你n种喷泉的价格和漂亮值,这n种喷泉题目指定用钻石或现金支付(分别用D和C表示),C ...

  6. ubuntu16.04中启动anaconda图形化界面

    $ source ~/anaconda3/bin/activate root $ anaconda-navigator

  7. 删除none的images

    脚本 #!/bin/bash docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker stop docker p ...

  8. JSON.parse()——json字符串转JS

    JSON 通常用于与服务端交换数据. 在接收服务器数据时一般是字符串. 我们可以使用 JSON.parse() 方法将数据转换为 JavaScript 对象. 语法 JSON.parse(text[, ...

  9. 笔记本自开wifi设置

    笔记本自开wifi设置 是这样的有些笔记本他自身就可以放出热点供其他的小伙伴们连接,不用非得去下专门的工具有些笔记本的网卡是自带支持双收发的(这里注意我指的是有些笔记本不是全部) 命令我已经写出来了  ...

  10. dlmalloc(一)【转】

    转自:http://blog.csdn.net/ycnian/article/details/12971863 我们写过很多C程序了,经常会分配内存.记得刚学C语言时老师说过,可以向两个地方申请内存: ...