hdu 1695 GCD(容斥)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} /********************************************************************/ const int maxn = 1e5+;
vector<int> pri[maxn]; //分解成的质数
void init(){
for(int i = ;i < maxn; i++){
int now = i;
for(int j = ;j*j <= now;j++){
if(now%j == ){
pri[i].push_back(j);
while(now%j == ) now /= j;
}
if(now == ) break;
}
if(now > )
pri[i].push_back(now);
}
} int solve(int x, int pos){
int res = ;
for(int i = ;i < ( << pri[x].size());i++){
int num = ;
int tmp = ;
for(int j = ;j < pri[x].size();j++){
if((i >> j)& ){
num++;
tmp *= pri[x][j];
}
}
if(num & ) res += pos/tmp;
else res -= pos/tmp;
}
return pos - res;
} int main(){
init();
int t;
t = read();
for(int i = ;i <= t;i++){
int a, b, c, d, k;
//a = 1, d = 1;
a = read(); b = read(); c = read(); d = read(); k = read();
if(k == ){
printf("Case %d: 0\n", i);
continue;
}
b /= k, d /= k;
if(b < d) swap(b, d);
ll ans = ;
for(int j = ;j <= b;j++){
ans += solve(j, min(j, d));
}
printf("Case %d: %lld\n", i, ans);
}
return ;
}
hdu 1695 GCD(容斥)的更多相关文章
- HDU 1695 GCD 容斥
GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1695 Description Given 5 integers: a, b, c, d, k ...
- hdu 1695 GCD 容斥+欧拉函数
题目链接 求 $ x\in[1, a] , y \in [1, b] $ 内 \(gcd(x, y) = k\)的(x, y)的对数. 问题等价于$ x\in[1, a/k] , y \in [1, ...
- HDU - 1695 GCD (容斥+枚举)
题意:求区间1<=i<=b与区间1<=j<=d之间满足gcd(i,j) = k 的数对 (i,j) 个数.(i,j)与(j,i) 算一个. 分析:gcd(i,j)=k可以转化为 ...
- hdu 5514 Frogs(容斥)
Frogs Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- HDU 5213 分块 容斥
给出n个数,给出m个询问,询问 区间[l,r] [u,v],在两个区间内分别取一个数,两个的和为k的对数数量. $k<=2*N$,$n <= 30000$ 发现可以容斥简化一个询问.一个询 ...
- HDU 2588 思维 容斥
求满足$1<=X<=N ,(X,N)>=M$的个数,其中$N, M (2<=N<=1000000000, 1<=M<=N)$. 首先,假定$(x, n)=m$ ...
- hdu 1695 GCD 欧拉函数 + 容斥
http://acm.hdu.edu.cn/showproblem.php?pid=1695 要求[L1, R1]和[L2, R2]中GCD是K的个数.那么只需要求[L1, R1 / K] 和 [L ...
- HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 1695 GCD(容斥定理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- 数论 + 容斥 - HDU 1695 GCD
problem's Link mean 给定五个数a,b,c,d,k,从1~a中选一个数x,1~b中选一个数y,使得gcd(x,y)=k. 求满足条件的pair(x,y)数. analyse 由于b, ...
随机推荐
- 在MFC中使用大漠插件
打开Class Wizard,Add Class...->MFC Class From TypeLib... File->Location->>> Finish-> ...
- HTML 常用组件
1.下拉选择 <select id="select" name="select" class="form-control"> & ...
- log4j(转)
让System.out.println回家种田,换句话说,就是该干嘛干嘛去. 您可能在想: System.out.println几乎在每个Java程序里都有那么几行,如何让他老人家回家种田呢? 我们怎 ...
- 相机标定过程(opencv) + matlab参数导入opencv + matlab标定和矫正
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 辛苦原创所得,转载请注明出处 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ...
- wireshark 学习 2
使用wireshark抓到的wifi数据包如果是加密的,就只能显示密文,无法得到真正的数据. 如果知道AP和SSID和key,就可以解密wifi数据包,显示上层协议的数据. 在wireshark中设置 ...
- 安装截图工具 Shutter【转】
本文转载自:http://blog.csdn.net/hanshileiai/article/details/46843713 一.安装截图工具 Shutter 1. 添加安装包软件源 sudo ad ...
- ZIP伪加密(deprecated)
ZIP伪加密 经过伪加密的apk,改成zip格式打开会发现里面的文件都经过了加密. APK实际上是Zip压缩文件,但是Android系统在解析APK文件时,和传统的解压压缩软件在解析Zip文件时存在差 ...
- ubuntu 下串口调试工具 minicom安装与配置
检查系统是否支持USB转串口: lsmod | grep usbserial 如果有usbserial,说明系统支持USB转串口. 识别串口设备: 插上USB转串口,在终端输入命令: #dmesg | ...
- EF之贪婪加载和延迟加载
这篇文章将讨论查询结果的控制 在使用EF(Entity Framework)的过程中,很多时候我们会进行查询的操作,因此知道哪些数据会被加载到内存当中就至关重要.在多多的情况下,你可能并并不需要加载全 ...
- A-Z,a-z,0-9的unicode编码表
1.转自:https://blog.csdn.net/fedawn/article/details/7307993 A-Z 的 Unicode 字符编码表 十进制 十六进制 1.“A”的 U ...