题意:

有一个\(n*n*n\)的三维直角坐标空间,问从\((0,0,0)\)看能看到几个点。

思路:

按题意研究一下就会发现题目所求为。

\[(\sum_{i=1}^n\sum_{j=1}^n\sum_{k=1}^n[gcd(i,j,k)==1])+(\sum_{i=1}^n\sum_{j=1}^n[gcd(i,j)==1])\\+(\sum_{i=1}^n\sum_{k=1}^n[gcd(i,k)==1])+(\sum_{j=1}^n\sum_{k=1}^n[gcd(j,k)==1])
\]

随便求其中一个,由莫比乌斯函数已知\(\sum_{d|n}\mu(d)=[n=1]\),替换可得

\[\sum_{i=1}^n\sum_{j=1}^n\sum_{k=1}^n\sum_{d|n}\mu(d)=\sum_{d=1}^n\mu(d)*\lfloor{\frac{n}{d}}\rfloor^3
\]

其他情况同理。

参考:

莫比乌斯反演-让我们从基础开始

代码:

#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1000000 + 5;
const int INF = 0x3f3f3f3f;
const ull seed = 131;
const ll MOD = 1e9;
using namespace std; int mu[maxn], vis[maxn];
int prime[maxn], cnt;
void getmu(int n){
memset(vis, 0, sizeof(vis));
memset(mu, 0, sizeof(mu));
cnt = 0;
mu[1] = 1;
for(int i = 2; i <= n; i++) {
if(!vis[i]){
prime[cnt++] = i;
mu[i] = -1;
}
for(int j = 0; j < cnt && prime[j] * i <= n; j++){
vis[prime[j] * i] = 1;
if(i % prime[j] == 0) break;
mu[i * prime[j]] = -mu[i];
}
}
}
ll get(int n){
return 1LL * n * n * n + 3LL * n * n + 3LL * n;
}
int main(){
int n, T;
getmu(1000000);
scanf("%d", &T);
while(T--){
scanf("%d", &n);
ll ans = 0;
for(int i = 1; i <= n; i++){
ans += 1LL * mu[i] * get(n / i);
}
printf("%lld\n", ans);
}
return 0;
}

SPOJ VLATTICE Visible Lattice Points(莫比乌斯反演)题解的更多相关文章

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

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

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

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

  4. spoj 7001 Visible Lattice Points莫比乌斯反演

    Visible Lattice Points Time Limit:7000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Su ...

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

    题意:求一个正方体里面,有多少个顶点可以在(0,0,0)位置直接看到,而不被其它点阻挡.也就是说有多少个(x,y,z)组合,满足gcd(x,y,z)==1或有一个0,另外的两个未知数gcd为1 定义f ...

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

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

  7. Spoj 7001 Visible Lattice Points 莫比乌斯,分块

    题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193   Visible Lattice Points Time L ...

  8. spoj7001 Visible Lattice Points 莫比乌斯反演+三维空间互质对数

    /** 题目:Visible Lattice Points 链接:https://vjudge.net/contest/178455#problem/A 题意:一个n*n*n大小的三维空间.一侧为(0 ...

  9. SPOJ VLATTICE - Visible Lattice Points 【“小”大数加减】

    题目链接 一道比较简单的莫比乌斯反演,不过ans会爆long long,我是用结构体来存结果的,结构体中两个LL型变量分别存大于1e17和小于1e17的部分 #include<bits/stdc ...

随机推荐

  1. printf函数输出格式总结

    printf函数格式 函数描述: printf("[格式化字符串]", [参数链表]); 函数声明: int printf(const char *format, ...) ; 输 ...

  2. Centos7 虚拟机优化

    配置yum源 rm -f /etc/yum.repos.d/* curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/ ...

  3. 前端知识(二)01-NPM包管理器-谷粒学院

    目录 一.简介 二.使用npm管理项目 1.项目初始化 2.修改npm镜像 3.npm install命令的使用 4.其它命令 一.简介 什么是NPM NPM全称Node Package Manage ...

  4. Flask源码关于local的实现

    flask源码关于local的实现 try: # 协程 from greenlet import getcurrent as get_ident except ImportError: try: fr ...

  5. 代码 or 指令,浅析ARM架构下的函数的调用过程

    摘要:linux程序运行的状态以及如何推导调用栈. 1.背景知识 1.ARM64寄存器介绍: 2.STP指令详解(ARMV8手册): 我们先看一下指令格式(64bit),以及指令对于寄存机执行结果的影 ...

  6. Cisco之show基础命令

    #show  version:显示版本信息等 #show running-config:显示当前(活动,并不一定保存)的配置 #show interfaces fastEthernet 0/1:进入接 ...

  7. Failed to start ssh.service: Unit not found.

    Failed to start ssh.service: Unit not found. 报错内容: [Centos7@localhost ~]$ service ssh start Redirect ...

  8. css选择器有哪些,选择器的权重的优先级

    选择器类型 1.ID #id 2.class .class 3.标签 p 4.通用 * 5.属性 [type="text"] 6.伪类 :hover 7.伪元素 ::first-l ...

  9. 数位DP笔记

    数位DP 1.定义: 数位dp是一种计数用的dp,一般就是要统计一个区间[L,R]内满足一些条件数的个数.所谓数位dp,字面意思就是在数位上进行dp: 数位的含义:一个数有个位.十位.百位.千位... ...

  10. Xctf-easyapk

    Xctf-easyapk Write UP 前期工作 查壳 无壳 运行 没什么特别的 逆向分析 使用jadx反编译查看代码 先看看文件结构 MainActivity代码 public class Ma ...