对于已经满足条件的(x1,y1),不满足条件的点就是(n*x1,n*y1),所以要求的就是满足点(x,y)的x,y互质,也就是gcd(x,y) == 1,然后就可以用之前多校的方法来做了

另f[i] 表示gcd为 i 的倍数的对数

g[i] 表示gcd == i 的对数

f[i] = (n/i) * (m/i)

g[i] = f[i] - g[x*i] (x>=2)

然后容斥出来的g[1]就是对数

#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lowbit(x) (x & (-x))
#define INOPEM freopen("in.txt", "r", stdin)
#define OUTOPEN freopen("out.txt", "w", stdout) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = ;
const int maxm = ;
const int mod = 1e9+;
using namespace std; int n, m;
int T, tol;
ll f[maxn];
ll g[maxn]; void init() {
memset(f, , sizeof f);
memset(g, , sizeof g);
} int main() {
scanf("%d", &T);
while(T--) {
init();
scanf("%d%d", &n, &m);
if(n > m) swap(n, m);
for(int i=; i<=n; i++) f[i] = 1ll * (n/i) * (m/i);
for(int i=n; i>=; i--) {
g[i] = f[i];
for(int j=; i*j<=n; j++) {
g[i] -= g[i*j];
}
}
printf("%lld\n", g[]);
}
return ;
}

Visible Trees HDU - 2841(容斥)的更多相关文章

  1. C - Visible Trees HDU - 2841 -莫比乌斯函数-容斥

    C - Visible Trees HDU - 2841 思路 :被挡住的那些点(x , y)肯定是 x 与 y不互质.能够由其他坐标的倍数表示,所以就转化成了求那些点 x,y互质 也就是在 1 - ...

  2. HDU 2841 容斥 或 反演

    $n,m <= 1e5$ ,$i<=n$,$j<=m$,求$(i⊥j)$对数 /** @Date : 2017-09-26 23:01:05 * @FileName: HDU 284 ...

  3. Visible Trees HDU - 2841

    Visible Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  4. - Visible Trees HDU - 2841 容斥原理

    题意: 给你一个n*m的矩形,在1到m行,和1到n列上都有一棵树,问你站在(0,0)位置能看到多少棵树 题解: 用(x,y)表示某棵树的位置,那么只要x与y互质,那么这棵树就能被看到.不互质的话说明前 ...

  5. HDU 4135 容斥

    问a,b区间内与n互质个数,a,b<=1e15,n<=1e9 n才1e9考虑分解对因子的组合进行容斥,因为19个最小的不同素数乘积即已大于LL了,枚举状态复杂度不会很高.然后差分就好了. ...

  6. HDU 1695 容斥

    又是求gcd=k的题,稍微有点不同的是,(i,j)有偏序关系,直接分块好像会出现问题,还好数据规模很小,直接暴力求就行了. /** @Date : 2017-09-15 18:21:35 * @Fil ...

  7. HDU 4059 容斥初步练习

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

  8. hdu 1220 容斥

    http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  9. Co-prime HDU - 4135_容斥计数

    Code: #include<cstdio> #include<cstring> #include<cmath> #include<iostream> ...

随机推荐

  1. MySQL :: Fatal error: Can&#039;t change to run as user &#039;mysql&#039;. Please check that the user exists!

    Fatal error: Can't change to run as user 'mysql'. Please check that the user exists! MySQL :: Fatal ...

  2. b,B,KB,MB,GB,TB,PB,EB,ZB,YB,BB,NB,DB的含义,之间的关系

    1bit=1位2进制信息 1B (byte 字节)1KB(Kilobyte 千字节)=2(10)B=1024B=2(10)B: 1MB(Megabyte 兆字节)=2(10)KB=1024KB=2(2 ...

  3. Azure系列2.1.1 —— BlobContainerPermissions

    (小弟自学Azure,文中有不正确之处,请路过各位大神指正.) 网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习 ...

  4. Farm Irrigation

    题目:Farm Irrigation 题目链接:http://210.34.193.66:8080/vj/Problem.jsp?pid=1494 题目思路:并查集 #include<stdio ...

  5. Oracle 修改数据库表数据提交之后进行回滚

    --查看历史数据 select * from test1 as of timestamp to_timestamp('2018-12-23 14:41:00', 'yyyy-mm-dd hh24:mi ...

  6. js对input框的可编辑属性设置

    添加disabled属性 $('#areaSelect').attr("disabled",true); $('#areaSelect').attr("disabled& ...

  7. 原生JS实现增加删除class

    <!DOCTYPE html> <html> <head> <style type="text/css"> .night-mode{ ...

  8. Python rsa公私钥生成 rsa公钥加解密(分段加解密)-私钥加签验签实战

    一般现在的SAAS服务提供现在的sdk或api对接服务都涉及到一个身份验证和数据加密的问题.一般现在普遍的做法就是配置使用非对称加密的方式来解决这个问题,你持有SAAS公司的公钥,SAAS公司持有你的 ...

  9. spring 给一个类 生成test

    右击一个类,然后:GoTo==>test ,就可以新建这个类的测试用例了,简单粗暴, 如果想要不污染数据库,就在一个测试用例 的标签@Test 下面在加上@RollBack 这样: @Test ...

  10. jquery的show()和hide()方法

    显示和隐藏元素的方法 相当于CSS中的display属性 show()方法,相当于display:block hide()方法,相当于display:none