Spoj 7001 Visible Lattice Points 莫比乌斯,分块
| Time Limit: 1368MS | Memory Limit: 1572864KB | 64bit IO Format: %lld & %llu |
Description
Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many lattice points are visible from corner at (0,0,0) ? A point X is visible from point Y iff no other lattice point lies on the segment joining X and Y.
Input :
The first line contains the number of test cases T. The next T lines contain an interger N
Output :
Output T lines, one corresponding to each test case.
Sample Input :
3
1
2
5
Sample Output :
7
19
175
Constraints :
T <= 50
1 <= N <= 1000000
Hint
#include<bits/stdc++.h>
using namespace std;
#define MAXN 1000010
#define LL long long
int mu[MAXN+],prime[],qz[MAXN+],tot;
bitset<MAXN+> vis;
int read()
{
int s=,fh=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')fh=-;ch=getchar();}
while(ch>=''&&ch<=''){s=s*+(ch-'');ch=getchar();}
return s*fh;
}
void getmu()
{
int i,j;
mu[]=;tot=;
for(i=;i<=MAXN;i++)
{
if(vis[i]==)
{
prime[++tot]=i;
mu[i]=-;
}
for(j=;j<=tot&&prime[j]*i<=MAXN;j++)
{
vis[prime[j]*i]=;
if(i%prime[j]==)
{
mu[prime[j]*i]=;
break;
}
mu[prime[j]*i]=-mu[i];
}
}
}
void Qz()
{
for(int i=;i<=MAXN;i++)qz[i]=qz[i-]+mu[i];
}
LL calc2(int n)//计算平面上的个数.
{
int d,pos;
LL sum=;
for(d=;d<=n;d=pos+)
{
pos=n/(n/d);
sum+=(LL)(qz[pos]-qz[d-])*(n/d)*(n/d);
}
return sum;
}
LL calc3(int n)//计算空间里的个数.
{
int d,pos;
LL sum=;
for(d=;d<=n;d=pos+)
{
pos=n/(n/d);
sum+=(LL)(qz[pos]-qz[d-])*(n/d)*(n/d)*(n/d);
}
return sum;
}
int main()
{
int N,T;
T=read();
getmu();
Qz();
while(T--)
{
N=read();
printf("%lld\n",calc3(N)+calc2(N)*+);
}
fclose(stdin);
fclose(stdout);
return ;
}
Spoj 7001 Visible Lattice Points 莫比乌斯,分块的更多相关文章
- 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 7001. Visible Lattice Points GCD问题 莫比乌斯反演
SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...
- SPOJ 7001. 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 (莫比乌斯反演基础题)
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 VLATTICE]Visible Lattice Points 数论 莫比乌斯反演
7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0, ...
- spoj7001 Visible Lattice Points 莫比乌斯反演+三维空间互质对数
/** 题目:Visible Lattice Points 链接:https://vjudge.net/contest/178455#problem/A 题意:一个n*n*n大小的三维空间.一侧为(0 ...
随机推荐
- 创建Java线程池
线程池的作用: 线程池作用就是限制系统中执行线程的数量. 根据系统的环境情况,可以自动或手动设置线程数量,达到运行的最佳效果:少了浪费了系统资源,多了造成系统拥挤效率不高.用线程池控制线程数量,其他线 ...
- ZOJ 1004 Anagrams by Stack(DFS+数据结构)
Anagrams by Stack 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4 题目大意:输入两个字符串序列,判 ...
- 283. Move Zeroes(C++)
283. Move Zeroes Given an array nums, write a function to move all 0's to the end of it while mainta ...
- 《paste命令》-linux命令五分钟系列之二十
本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...
- Centos6.5最小化安装:配置网络和自启动服务
参考http://www.111cn.net/sys/CentOS/56456.htm 1.开启网络连接,禁止IPV6启用 1.开启网络连接 vi /etc/sysconfig/network-sc ...
- Git关联远程GitHub仓库
一.本地安装GIT版本控制软件 二.配置Git,设置用户信息 git config --global user.name "jack" git config --global us ...
- 2016022604 - redis命令介绍
Redis keys命令用于在Redis的管理键. Redis keys命令使用语法如下所示: redis最新版本目前是3.0.7 redis 127.0.0.1:6379> COMMAND K ...
- MFC 之ActiveX控件学习
本文将介绍ActiveX控件的应用与工作原理,读者可以把ActiveX控件看成一个极小服务器的应用程序,它不能独立运行,必须要嵌入到容器程序中与容器一起运行,就像电脑主机中的显卡,它自己在电脑硬件系统 ...
- 十六进制字符串转化为byte数组
工作上有这样的需求之前找了好多都不行,好不容易有个可以的赶紧留下来. 原址:http://blog.163.com/roadwalker@126/blog/static/113561841201013 ...
- Hadoop 学习笔记 (十) hadoop2.2.0 生产环境部署 HDFS HA Federation 含Yarn部署
其他的配置跟HDFS-HA部署方式完全一样.但JournalNOde的配置不一样>hadoop-cluster1中的nn1和nn2和hadoop-cluster2中的nn3和nn4可以公用同样的 ...