GCD(莫比乌斯+去重)
莫比乌斯反演模板题, 去重即可;
我们可以发现只有在区间重叠部分才会有重复且为cal(e, e, k)/2;(e表示b, d中较小的一个);
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn = ; int a,b,c,d,k;
ll pri[maxn],vis[maxn],mu[maxn]; void init()
{ mu[] = ;
int cnt = ;
for(int i = ; i <= maxn; i++)
{
if(vis[i] == ) {
pri[cnt++] = i;
mu[i] = -;
}
for(int j = ; j < cnt&&i*pri[j] <= maxn; j++)
{
ll k = i*pri[j];
vis[k] = ;
if(i%pri[j] == ) {mu[k]= ; break;}
else mu[k] = -mu[i];
}
}
for(int i = ; i <= maxn; i++)
mu[i] += mu[i-];
} ll cal(int l, int r, int k) // 神奇的分块
{
if(!l||!r||!k) return ;
if(l > r) swap(l, r);
l /= k, r /= k;
int last = ;
ll ans = ;
for(int i = ; i <= l; i = last+)
{
last = min( l/(l/i), r/(r/i) );
ans += ( mu[last] - mu[i-] )*(l/i)*(r/i);
}
return ans;
} int main()
{
ios::sync_with_stdio(false);
init();
int n;
cin >> n;
int i = ;
while(i <= n)
{
cin >> a >> b >> c >> d >> k;
int e = min(b,d);
ll ans = cal(b, d, k) - cal(e, e, k)/;
// printf("Case %d: %lld\n", i, ans);
cout << "Case " << i << ": " << ans << endl;
i++;
} return ;
}
GCD(莫比乌斯+去重)的更多相关文章
- [BZOJ 2820] YY的gcd(莫比乌斯反演+数论分块)
[BZOJ 2820] YY的gcd(莫比乌斯反演+数论分块) 题面 给定N, M,求\(1\leq x\leq N, 1\leq y\leq M\)且gcd(x, y)为质数的(x, y)有多少对. ...
- hdu 1695 GCD 莫比乌斯反演入门
GCD 题意:输入5个数a,b,c,d,k;(a = c = 1, 0 < b,d,k <= 100000);问有多少对a <= p <= b, c <= q <= ...
- HDU1695 GCD(莫比乌斯反演)
传送门 看了1个多小时,终于懂了一点了 题目大意:给n,m,k.求gcd(x,y) = k(1<=x<=n, 1<=y<=m)的个数 思路:令F(i)表示i|gcd(x,y)的 ...
- Bzoj 2818: Gcd 莫比乌斯,分块,欧拉函数,线性筛
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 3241 Solved: 1437[Submit][Status][Discuss ...
- 洛谷P2257 YY的GCD 莫比乌斯反演
原题链接 差不多算自己推出来的第一道题QwQ 题目大意 \(T\)组询问,每次问你\(1\leqslant x\leqslant N\),\(1\leqslant y\leqslant M\)中有多少 ...
- bzoj 2820 YY的GCD - 莫比乌斯反演 - 线性筛
Description 神犇YY虐完数论后给傻×kAc出了一题给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对kAc这种 傻×必 ...
- HihoCoder - 1867: GCD (莫比乌斯容斥)
Sample Input 6 1 6 2 5 3 4 Sample Output 10 You are given a {1, 2, ..., n}-permutation a[1], a[2], . ...
- HYSBZ - 2818 Gcd (莫比乌斯反演)
莫比乌斯反演的入门题,设 \(F(x): gcd(i,j)\%x=0\) 的对数,\(f(x): gcd(i,j)=x\)的对数. 易知\[F(p) = \lfloor \frac{n}{p} \rf ...
- 【BZOJ2818】Gcd [莫比乌斯反演]
Gcd Time Limit: 10 Sec Memory Limit: 256 MB[Submit][Status][Discuss] Description 给定整数N,求1<=x,y&l ...
随机推荐
- 转:Java properties | FileNotFoundException: properties (系统找不到指定的文件。)
原文地址:https://blog.csdn.net/cor_twi/article/details/44514871 web项目 (dynamic web project ) 读取propertie ...
- ubuntu安装jupyter 并设置远程访问
Jupyter Notebook是一个Web应用程序,允许您创建和共享包含实时代码,方程,可视化和说明文本的文档. 简单的介绍就是:Jupyter Notebook是Ipython的升级版,而Ipyt ...
- 关于WARN Dispatcher:68 - Could not find action or result报错
出现这个错 00:03:37,142 WARN Dispatcher:68 - Could not find action or result: /crm/linkMan_addLinkMan.act ...
- Java Web----------response&&request
1.response 代表响应, 可以理解为一个空的箱子,我们在里面填入要发送到浏览器的内容. 服务器会把这些内容组装成http响应. 1.1 响应首行 协议/版本号 状态码 状态码描述 添加状态码 ...
- centos 关闭selinux
将SELINUX配置文件设置为 disabled 模式,禁用SELinux vim /etc/selinux/config SELINUX=disabled 然后reboot重启生效 setenfor ...
- 【环境配置】配置jdk
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/manoel/article/details/37736569 1. 下载jdk的安装文件 http: ...
- 20180318 一个VS2015运行DataTable问题
1. 环境VS 2015 社区版,使用"DataTable" 为了即使查看DataTable中的数据,点击放大镜 ,加载提示错误. 解决方案: 第一步: 第二步: “选项” -- ...
- Java中的boxing和unboxing(转)
测试代码: System.out.println(0L == 0);//true System.out.println(((Long)0L).equals(0));//false Integer i1 ...
- java -jstack
一.介绍 jstack是java虚拟机自带的一种堆栈跟踪工具.jstack用于打印出给定的java进程ID或core file或远程调试服务的Java堆栈信息,如果是在64位机器上,需要指定选项&qu ...
- GIT中常用的命令
最近项目中使用到了GIT,所以记录一下GIT中常用的命令. GIT使用的客户端有Git Bash:http://code.google.com/p/msysgit/ 还有乌龟TortoiseGit:h ...