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 ...
随机推荐
- 【JZOJ4884】【NOIP2016提高A组集训第12场11.10】图的半径
题目描述 mhy12345学习了树的直径,于是开始研究图的半径,具体来说,我们需要在图中选定一个地方作为中心,其中这个中心有可能在路径上. 而这个中心的选址需要能够使得所有节点达到这个中心的最短路里面 ...
- 【Django入坑之路】基础操作(过滤,继承,跳转)
1:自定过滤器 1创建templatetags文件夹 2在里面创建自定义py文件:固定格式: from django import template from django.utils.safestr ...
- 2019-9-2-win10-uwp-右击浮出窗在点击位置
title author date CreateTime categories win10 uwp 右击浮出窗在点击位置 lindexi 2019-09-02 12:57:38 +0800 2018- ...
- python 语法错误
- Effective C++: 01让自己习惯C++
01:视C++为一个语言联邦 1:今天的C++已经是个多重范型编程语言(multiparadigm programming language),一个同时支持过程形式(procedural).面向对象形 ...
- spider csdn blog part II
继续上次的笔记, 继续完善csdn博文的提取. 发现了非常好的模块. html2docx 结果展示: 运行之后, 直接生成docx文档. 截个图如下: 结果已经基本满意了!!! 在编写过程中的一些感想 ...
- find 使用搜集
find:-atime +n/-n:表示访问或执行时间大于或小于n天的文件-ctime +n/-n:表示写入.更改inode属性的时间大于或小于n天的文件-mtime +n/-n:表示写入时间大于或小 ...
- iOS 11 适配UIWebView,页面下移20的问题
方案1: AppDelegate文件 didFinishLaunchingWithOptions()中添加如下代码 if (@available(iOS 11.0, *)) { [[UIScrollV ...
- 无人驾驶——对frenet坐标的理解
好的确定车和路之间的关系,我们通常将车辆的在大地坐标坐标转化为车辆和道路之间的frenet坐标. 可能有人会疑问为什么转换后就方便了呢?我们来看一个例子. 在大地坐标下: 无人车首先要知道红色车的位置 ...
- oracle函数 RTRIM(c1,[,c2])
[功能]删除右边出现的字符串 [参数]C1 字符串 c2 追加字符串,默认为空格 [返回]字符型 [示例] SQL> select RTRIM('gao qian jingXXXX','X') ...