SPOJ VLATTICE (莫比乌斯反演)
传送门:https://www.spoj.com/problems/VLATTICE/en/
题意:
在三维坐标系下,你在点(0,0,0),看的范围是(n,n,n)以内,求你可以看见多少个点没有被遮挡
题解:
一条线上的点肯定是会被挡的
所以我们求的是\(gcd(x,y,z)==1\)的组数
我们设
F(d):d|gcd(x,y,z)的对数\\
由于F(d)为[n/d]*[n/d]*[n/d]\\
所以反演可得\\
f(1)=mu[d]*[n/d]*[n/d]*[n/d]\\
由于坐标系上的点也要算的话\\
1.我们的点(0,0,1)、(1,0,1)、(0,1,1)\\
2.xoy,xoz,xoy面上的点gcd(i,j)==1; \\
3.其他点 gcd(i,j,k)==1
\]
代码:
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef long long ll;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3f;
int mu[maxn];
int prime[maxn];
int not_prime[maxn];
int tot;
void Mobiwus(int n) {
mu[1] = 1;
for(int i = 2; i <= n; i++) {
if(!not_prime[i]) {
prime[++tot] = i;
mu[i] = -1;
}
for(int j = 1; prime[j]*i <= n; j++) {
not_prime[prime[j]*i] = 1;
if(i % prime[j] == 0) {
mu[prime[j]*i] = 0;
break;
}
mu[prime[j]*i] = -mu[i];
}
}
}
int main() {
#ifndef ONLINE_JUDGE
FIN
#endif
int T;
Mobiwus(1000005);
scanf("%d", &T);
while(T--) {
int n;
scanf("%d", &n);
LL ans = 3;
for(int i = 1; i <= n; i++) {
ans += 1LL * mu[i] * (n / i) * (n / i) * (n / i);
}
for(int i = 1; i <= n; i++) {
ans += 1LL * mu[i] * (n / i) * (n / i) * 3;
}
printf("%lld\n", ans);
}
return 0;
}
SPOJ VLATTICE (莫比乌斯反演)的更多相关文章
- SPOJ - VLATTICE (莫比乌斯反演)
Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many latt ...
- SPOJ PGCD(莫比乌斯反演)
传送门:Primes in GCD Table 题意:给定两个数和,其中,,求为质数的有多少对?其中和的范围是. 分析:这题不能枚举质数来进行莫比乌斯反演,得预处理出∑υ(n/p)(n%p==0). ...
- bzoj 2820 / SPOJ PGCD 莫比乌斯反演
那啥bzoj2818也是一样的,突然想起来好像拿来当周赛的练习题过,用欧拉函数写掉的. 求$(i,j)=prime$对数 \begin{eqnarray*}\sum_{i=1}^{n}\sum_{j= ...
- SPOJ 7001(莫比乌斯反演)
传送门:Visible Lattice Points 题意:0<=x,y,z<=n,求有多少对xyz满足gcd(x,y,z)=1. 设f(d) = GCD(a,b,c) = d的种类数 : ...
- SPOJ 7001 VLATTICE - Visible Lattice Points(莫比乌斯反演)
题目链接:http://www.spoj.com/problems/VLATTICE/ 题意:求gcd(a, b, c) = 1 a,b,c <=N 的对数. 思路:我们令函数g(x)为g ...
- SPOJ VLATTICE Visible Lattice Points 莫比乌斯反演 难度:3
http://www.spoj.com/problems/VLATTICE/ 明显,当gcd(x,y,z)=k,k!=1时,(x,y,z)被(x/k,y/k,z/k)遮挡,所以这道题要求的是gcd(x ...
- SPOJ VLATTICE Visible Lattice Points (莫比乌斯反演基础题)
Visible Lattice Points Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at ...
- [SPOJ VLATTICE]Visible Lattice Points 数论 莫比乌斯反演
7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0, ...
- SPOJ VLATTICE Visible Lattice Points 莫比乌斯反演
这样的点分成三类 1 不含0,要求三个数的最大公约数为1 2 含一个0,两个非零数互质 3 含两个0,这样的数只有三个,可以讨论 针对 1情况 定义f[n]为所有满足三个数最大公约数为n的三元组数量 ...
- SPOJ VLATTICE Visible Lattice Points(莫比乌斯反演)题解
题意: 有一个\(n*n*n\)的三维直角坐标空间,问从\((0,0,0)\)看能看到几个点. 思路: 按题意研究一下就会发现题目所求为. \[(\sum_{i=1}^n\sum_{j=1}^n\su ...
随机推荐
- python 自主控制异常:用户自定义异常
- Java练习 SDUT-3268_飞花的糖果
飞花的糖果 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 一日,飞花壕大手一挥,买了N个的两两不相同糖果,他想要拿出M ...
- GDB调试命令手册
使用GDB 启动 $ gdb program # program是你的可执行文件,一般在当前目录 $ gdb program core # gdb同时调试运行程序和cor ...
- Apache利用mod_limitipconn模块限制客户端多线程下载
由于网站几次被人以搞并发弄跨了,所以百度了一堆方法.其中有一篇针对apache的能限制ip访问量.不允许同一ip大并发访问. 安装模块 yum install mod_limitipconn.x86_ ...
- SLS机器学习最佳实战:日志聚类+异常告警
1.手中的锤子都有啥? 围绕日志,挖掘其中更大价值,一直是我们团队所关注.在原有日志实时查询基础上,今年SLS在DevOps领域完善了如下功能: 上下文查询 实时Tail和智能聚类,以提高问题调查效率 ...
- 全文索引——CONTAINS 语法
Like直接在数据据中查找可以查到所有所需记录但是会扫描整个表会影响性能CONTAINS是基于全文索引进行查询,查询结果受系统全文索引分词的方法影响查询结果会不全.Select * FROM A Wh ...
- Shell 基本运算符 1
Shell 和其他编程语言一样,支持多种运算符,包括: 算术运算符 关系运算符 字符串运算符 文件测试运算符 原生bash不支持简单的数学运算,但是可以通过其他命令来实现,例如 awk 和 expr ...
- 如何使用jmeter调用soap协议
- 通过GDB重新获得进程的输出
有时通过SecureCRT或者Putty远程ssh到主机上执行某个进程,因长时间没有交互导致ssh断链,此时该进程由init进程收留.该进程的输出也就无法获得了. 这种情况下,可以利用gdb重新获得该 ...
- 学习框架/对象onbeforeunload事件
1.有没有发现在一些表单提交页面,当我们点击页面某个链接要离开表单提交页面时会弹出一个提示信息,如下: 那么,这是提示是怎么产生的呢?代码如下: window.onbeforeunload=funct ...