SPOJ—VLATTICE Visible Lattice Points(莫比乌斯反演)
http://www.spoj.com/problems/VLATTICE/en/
题意:
给一个长度为N的正方形,从(0,0,0)能看到多少个点。
思路:
这道题其实和能量采集是差不多的,只不过从二维上升到了三维。
分三部分计算:
①坐标值上的点,只有3个。
②与原点相邻的三个表面上的点,需满足gcd(x,y)=1。
③其余空间中的点,需满足gcd(x,y,z)=1。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = + ; bool check[maxn];
int prime[maxn];
int mu[maxn];
ll sum[maxn]; void Mobius()
{
memset(check, false, sizeof(check));
mu[] = ;
int tot = ;
for (int i = ; i <= maxn; i++)
{
if (!check[i])
{
prime[tot++] = i;
mu[i] = -;
}
for (int j = ; j < tot; j++)
{
if (i * prime[j] > maxn)
{
break;
}
check[i * prime[j]] = true;
if (i % prime[j] == )
{
mu[i * prime[j]] = ;
break;
}
else
{
mu[i * prime[j]] = -mu[i];
}
}
}
sum[]=;
for(int i=;i<maxn;i++)
sum[i]=sum[i-]+mu[i];
return ;
} ll compute1(int n)
{
ll tmp=;
for(int i=,last=;i<=n;i=last+)
{
last=n/(n/i);
tmp+=(sum[last]-sum[i-])*(n/i)*(n/i)*(n/i);
}
return tmp;
} ll compute2(int n)
{
ll tmp=;
for(int i=,last=;i<=n;i=last+)
{
last=n/(n/i);
tmp+=(sum[last]-sum[i-])*(n/i)*(n/i);
}
return tmp;
} int n, m; int main()
{
//freopen("in.txt","r",stdin);
Mobius();
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
printf("%lld\n",compute1(n)+compute2(n)*+);
}
return ;
}
SPOJ—VLATTICE Visible Lattice Points(莫比乌斯反演)的更多相关文章
- 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 莫比乌斯反演 难度: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 莫比乌斯反演
这样的点分成三类 1 不含0,要求三个数的最大公约数为1 2 含一个0,两个非零数互质 3 含两个0,这样的数只有三个,可以讨论 针对 1情况 定义f[n]为所有满足三个数最大公约数为n的三元组数量 ...
- spoj 7001 Visible Lattice Points莫比乌斯反演
Visible Lattice Points Time Limit:7000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Su ...
- SPOJ 7001 Visible Lattice Points (莫比乌斯反演)
题意:求一个正方体里面,有多少个顶点可以在(0,0,0)位置直接看到,而不被其它点阻挡.也就是说有多少个(x,y,z)组合,满足gcd(x,y,z)==1或有一个0,另外的两个未知数gcd为1 定义f ...
- [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 7001 Visible Lattice Points 莫比乌斯,分块
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193 Visible Lattice Points Time L ...
- spoj7001 Visible Lattice Points 莫比乌斯反演+三维空间互质对数
/** 题目:Visible Lattice Points 链接:https://vjudge.net/contest/178455#problem/A 题意:一个n*n*n大小的三维空间.一侧为(0 ...
- SPOJ VLATTICE Visible Lattice Points(莫比乌斯反演)题解
题意: 有一个\(n*n*n\)的三维直角坐标空间,问从\((0,0,0)\)看能看到几个点. 思路: 按题意研究一下就会发现题目所求为. \[(\sum_{i=1}^n\sum_{j=1}^n\su ...
- SPOJ VLATTICE - Visible Lattice Points 【“小”大数加减】
题目链接 一道比较简单的莫比乌斯反演,不过ans会爆long long,我是用结构体来存结果的,结构体中两个LL型变量分别存大于1e17和小于1e17的部分 #include<bits/stdc ...
随机推荐
- [SCOI2008] 着色方案[高维dp]
321. [SCOI2008] 着色方案 ★★★ 输入文件:color.in 输出文件:color.out 简单对比时间限制:1 s 内存限制:64 MB 题目背景: 有n个木块排成一 ...
- weblogic新漏洞学习cve-2017-10271
一.原理: 很明显啦,readobject又出来背锅了,一个XML的反序列化漏洞导致的命令执行. 具体原理我看不懂java代码的我也只能学习别人的分析.给出一篇参考文章,写的非常详细: 漏洞原理 二. ...
- 阿里云搭建SVN服务器
1:安装svn apt-get install subversion 2. 开启svn服务器 svnserve -d 检查是否开启:ps aux | grep svnserve 若出现如下内容: wk ...
- 使用angular路由切换后 轮播以及iscrollJs失效的问题
我们在使用angular的时候,路由总是最让人头疼的地方. 在这里为大家解决一些用angular来回切换遗留下的小问题 比如我们在使用ng-route时如果主页面含有轮播图,当你切换到其他页面再切回主 ...
- 使用colmap进行稠密重建
colmap应该是目前state-of-art的增量式SFM方案,可以方便的对一系列二维图片进行三维重建 不用对摄像机进行标定,只需要从不同角度对重建场景或物体进行拍摄得到一系列图像作为输入 首先需要 ...
- pandas的merge方法
数据合并时可以使用merge方法,对两个dataFrame根据某一个series合并,这个方法非常好用,只要找到了合并的标准,新的数据就可以重构出来. 1.命令: pd.merge() on:列名,j ...
- Oracle体系结构之Oracle分区
目录 Oracle分区 0 一.Oracle分区理论知识 1 二.分区表的实现方式 1 1.范围分区(range partition table) 1 2.列表分区(list partitioning ...
- php中 const 与define()的区别 ,选择
来自: http://stackoverflow.com/questions/2447791/define-vs-const 相同点: 两者都可以定义常量 const FOO = 'BAR'; def ...
- IoC COntainer Create Javabeans 可以通过读取beans.xml 文件来创建一个应用程序上下文对象 依赖反转
Spring初学快速入门 - Spring教程™ https://www.yiibai.com/spring/spring-tutorial-for-beginners.html# pom <? ...
- Linux 系统默认运行级别设定
#vi /etc/inittab,将 id:5:initdefault: 改为 id:3:initdefault: Linux 系统任何时候都运行在一个指定的运行级上,并且不同的运行级的程序和服务都不 ...