传送门:https://www.spoj.com/problems/VLATTICE/en/

题意:

在三维坐标系下,你在点(0,0,0),看的范围是(n,n,n)以内,求你可以看见多少个点没有被遮挡

题解:

一条线上的点肯定是会被挡的

所以我们求的是\(gcd(x,y,z)==1\)的组数

我们设

\[f(d):gcd(x,y,z)=d的对数\\
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 (莫比乌斯反演)的更多相关文章

  1. 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 ...

  2. SPOJ PGCD(莫比乌斯反演)

    传送门:Primes in GCD Table 题意:给定两个数和,其中,,求为质数的有多少对?其中和的范围是. 分析:这题不能枚举质数来进行莫比乌斯反演,得预处理出∑υ(n/p)(n%p==0). ...

  3. bzoj 2820 / SPOJ PGCD 莫比乌斯反演

    那啥bzoj2818也是一样的,突然想起来好像拿来当周赛的练习题过,用欧拉函数写掉的. 求$(i,j)=prime$对数 \begin{eqnarray*}\sum_{i=1}^{n}\sum_{j= ...

  4. SPOJ 7001(莫比乌斯反演)

    传送门:Visible Lattice Points 题意:0<=x,y,z<=n,求有多少对xyz满足gcd(x,y,z)=1. 设f(d) = GCD(a,b,c) = d的种类数 : ...

  5. SPOJ 7001 VLATTICE - Visible Lattice Points(莫比乌斯反演)

    题目链接:http://www.spoj.com/problems/VLATTICE/ 题意:求gcd(a, b, c) = 1    a,b,c <=N 的对数. 思路:我们令函数g(x)为g ...

  6. 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 ...

  7. 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 ...

  8. [SPOJ VLATTICE]Visible Lattice Points 数论 莫比乌斯反演

    7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0, ...

  9. SPOJ VLATTICE Visible Lattice Points 莫比乌斯反演

    这样的点分成三类 1 不含0,要求三个数的最大公约数为1 2 含一个0,两个非零数互质 3 含两个0,这样的数只有三个,可以讨论 针对 1情况 定义f[n]为所有满足三个数最大公约数为n的三元组数量 ...

  10. SPOJ VLATTICE Visible Lattice Points(莫比乌斯反演)题解

    题意: 有一个\(n*n*n\)的三维直角坐标空间,问从\((0,0,0)\)看能看到几个点. 思路: 按题意研究一下就会发现题目所求为. \[(\sum_{i=1}^n\sum_{j=1}^n\su ...

随机推荐

  1. js遮罩

    1.1 背景半透明遮罩层样式 需要一个黑色(当然也可以其他)背景,且须设置为绝对定位,以下是项目中用到的css样式: /* 半透明的遮罩层 */ #overlay { background: #000 ...

  2. hdu5131 贪心

    #include<stdio.h> #include<string.h> #include<algorithm> #include<string> #i ...

  3. SED总结, mac上要加备份文件名,sort命令和对中文的处理

    使用sed批量改文件名 Sed批量去拓展名 |- dev.gb.conll06.raw |- test.gb.conll06.raw |- train.gb.conll06.raw 想要去掉其中的后缀 ...

  4. python 字典创建

  5. 洛谷P1910 L国的战斗之间谍

    //二维费用01背包 #include<bits/stdc++.h> using namespace std; ; ; ; int v1[maxn],v2[maxn],w[maxn],n, ...

  6. Javascript 严格模式下不允许删除一个不允许删除的属性

    如下代码,在严格模式下,如果删除 Object.prototype 浏览器会报错,目前 IE10 也支持 严格模式. <script> "use strict"; de ...

  7. bert 硬件要求

    https://github.com/google-research/bert BERT ***** New May 31st, 2019: Whole Word Masking Models *** ...

  8. jqLite

    一.关于DOM导航的jqLite方法 children() 返回一组子元素.这个方法的jqLite实现不支持jQuery所提供的选择器特性 eq(index) 从一个元素集合中返回指定索引下的元素 f ...

  9. C#的循环语句(四)

    一.while 循环(1).while 其实是for循环的变形写法for(int i = 1; i<=5;i++)  {循环体:} 上面的for循环可以写成int i= 1:for(;i< ...

  10. 9 个必须知道的实用 PHP 函数和功能 [转]

    9 个必须知道的实用 PHP 函数和功能 [转] 即使使用 PHP 多年,也会偶然发现一些未曾了解的函数和功能.其中有些是非常有用的,但没有得到充分利用.并不是所有人都会从头到尾一页一页地阅读手册和函 ...