Visible Lattice Points

题意 : 从(0,0,0)出发在(N,N,N)范围内有多少条不从重合的直线;我们只要求gcd(x,y,z) = 1; 的点有多少个就可以了;

比如 : 点(2,4,6)可以等价成(1,2,3)即经过(1,2,3)的线一定经过(2,4,6);

莫比乌斯反演的模板题, 由于点坐标可以为0 , 需要考虑 x, y, z 中两个为0 和一个为0 的情况 :

两个为0 时 : 有 三个点(在x , y, z 轴上); 一个为0 时 : mu[i] * (n/i) * (n/i) * 3;

即 : mu[i] * (n/i) * (n/i)* (n/i+3) + 3;

#include<iostream>
#include<cstring> using namespace std;
#define ll long long
const int maxn = ; ll mu[maxn], pri[maxn], T, cnt, vis[maxn]; void init()
{
memset(vis, , sizeof(vis));
memset(mu,,sizeof(mu));
mu[] = ;
cnt = ;
ll n = ;
for(ll i = ; i <= n; i++)
{
if(!vis[i])
{
mu[i] = -;
pri[cnt++] = i;
}
for(ll j = ; j < cnt&&i*pri[j] <= n; j++)
{
ll k = i*pri[j];
vis[k] = ;
if(i%pri[j] == ) {mu[k] = ; break;}
else mu[k] = -mu[i];
}
}
} int main()
{
// ios::sync_with_stdio(false); init();
cin >> T;
while(T--)
{
ll n;
cin >> n;
ll ans = ;
for(ll i = ; i <= n; i++)
ans += (ll)(mu[i] * (n/i) * (n/i)* (n/i+));
cout << ans << endl; }
return ; }

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. spoj7001 Visible Lattice Points 莫比乌斯反演+三维空间互质对数

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

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

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

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

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

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

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

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

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

    题目链接 /* http://www.spoj.com/problems/VLATTICE/ 题意:求一个n*n*n的晶体,有多少点可以在(0,0,0)处可以直接看到. 同BZOJ.2301 题目即要 ...

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

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

  9. spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演

    SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...

随机推荐

  1. 什么是restful api

    https://blog.csdn.net/laotianv5/article/details/81634997 什么是Restful API Restful API 从字面就可以知道,他是rest式 ...

  2. LeetCode 811 Subdomain Visit Count 解题报告

    题目要求 A website domain like "discuss.leetcode.com" consists of various subdomains. At the t ...

  3. Java之旅_高级教程_Java Mysql连接(1)

    工具:Eclipse .mysql5.7 MySQL连接驱动:mysql-connector-java-5.1.27.jar    获取地址:https://dev.mysql.com/downloa ...

  4. linux 模拟发http请求的例子

    curl -X POST --header "Content-Type: application/json" --header "Accept: */*" &q ...

  5. kubernetes的CI/CD

    部署流程:把编码上传到gitlab上,使用webhook链接jenkins自动去编译docker镜像,然后上传到harbor本地docker镜像库中,再自动下载docker镜像,使用k8s控制dock ...

  6. Linux命令小计

    一.yum和apt-get的区别 Linux系统下安装包格式有:rpm包和deb包. pm包主要应用在RedHat系列包括 Fedora等发行版的Linux系统上 deb包主要应用于Debian系列包 ...

  7. es中如何定位不合法搜索

    GET /test_index/test_type/_validate/query?explain{ "query": { "math": { "te ...

  8. ZedBoard上运行linux系统的准备工作框架

    目标:ZedBoard上运行linux系统. 需要什么:图中上色部分. 应该做哪些工作:上色部分之前的所有步骤. 由上图得知,为了顺利在zedboard上构建嵌入式Linux操作系统,我们一般需要如下 ...

  9. django基础-01:软件框架,MVC框架,MVT

    1. 软件框架 一个公司是由公司中的各部部门来组成的,每一个部门拥有特定的职能,部门与部门之间通过相互的配合来完成让公司运转起来. 一个软件框架是由其中各个软件模块组成的,每一个模块都有特定的功能,模 ...

  10. 20170811 JQuery基础知识学习记录(一)

    基本写法 $(selector).action() $(this).hide() - 隐藏当前元素 $("p").hide() - 隐藏所有 <p> 元素 $(&quo ...