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

C - Visible Trees HDU - 2841 思路 :被挡住的那些点(x , y)肯定是 x 与 y不互质.能够由其他坐标的倍数表示,所以就转化成了求那些点 x,y互质 也就是在 1 - m    1 - n 中找互质的对数,容斥 求一下即可 #include<bits/stdc++.h> using namespace std; #define ll long long #define maxn 123456 bool vis[maxn+10]; ll t,n,m,prime[m…
$n,m <= 1e5$ ,$i<=n$,$j<=m$,求$(i⊥j)$对数 /** @Date : 2017-09-26 23:01:05 * @FileName: HDU 2841 容斥 或 反演.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : $Id$ */ #include <bits/stdc++.h…
对于已经满足条件的(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<…
Visible Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4331    Accepted Submission(s): 1991 Problem Description There are many trees forming a m * n grid, the grid starts from (1,1). Farm…
题意: 给你一个n*m的矩形,在1到m行,和1到n列上都有一棵树,问你站在(0,0)位置能看到多少棵树 题解: 用(x,y)表示某棵树的位置,那么只要x与y互质,那么这棵树就能被看到.不互质的话说明前面已经有树挡住了这棵树 i是[1,m]中的任意一个数 我们可以for循环求在区间[1,n]内有多少数与i互质 求法就是容斥原理,具体见这里:HDU - 4135 容斥原理 代码: 1 /* 2 题意: 3 给你一个n*m的矩形,在1到m行,和1到n列上都有一棵树,问你站在(0,0)位置能看到多少棵树…
问a,b区间内与n互质个数,a,b<=1e15,n<=1e9 n才1e9考虑分解对因子的组合进行容斥,因为19个最小的不同素数乘积即已大于LL了,枚举状态复杂度不会很高.然后差分就好了. /** @Date : 2017-09-28 16:52:30 * @FileName: HDU 4135 容斥.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/…
又是求gcd=k的题,稍微有点不同的是,(i,j)有偏序关系,直接分块好像会出现问题,还好数据规模很小,直接暴力求就行了. /** @Date : 2017-09-15 18:21:35 * @FileName: HDU 1695 容斥 或 莫比乌斯反演.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : $Id$ */ #in…
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #define LL long long using namespace std; ; ; LL Factor[],cnt,n,m,tot,Rev,Kase,Prime[Maxn]; bool vis[Maxn]; inline LL Quick_Pow(LL x,LL y) { LL Ret=; whi…
http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2260    Accepted Submission(s): 1819 Problem Description Cowl is good at solving math problems…
Code: #include<cstdio> #include<cstring> #include<cmath> #include<iostream> using namespace std; const int maxn=100000+233; typedef long long ll; int v[maxn],vis[maxn]; int m[maxn]; int num; //质因子个数 ll ans=0; ll A,B; ll gcd(ll a,ll…