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 ...
随机推荐
- 消息处理之EventBus ——使用篇
以前的几篇文章简单的介绍了一下UI线程和子线程之间的线程通信利器Handler,以及顺便介绍了一下SyncTask和HeadlerThread.这里介绍另一线程通信利器EventBus. EventB ...
- window.event对象详细介绍
1.event代表事件的状态,例如触发event对象的元素.鼠标的位置及状态.按下的键等等.event对象只在事件发生的过程中才有效.event的某些属性只对特定的事件有意义.比如,fromEleme ...
- iOS 获取URL中的参数
- (NSString *)getParamByName:(NSString *)name URLString:(NSString *)url { NSError *error; NSString * ...
- 数据库(学习整理)----2--关于Oracle用户权限的授权和收权
知识点: 1.Oracle数据库中所用的用户等级是平级的!只是每个用户的权限不同而已! 2.在一个用户登录后,可以在自己的登录状态下访问其他用户的数据缓冲区.表.以及表的操作!(只要该用户用权限!) ...
- 转载:Python正则表达式
原文在 http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html 1. 正则表达式基础 1.1. 简单介绍 正则表达式并不是Python ...
- (三)跟我一起玩Linux网络服务:DHCP服务配置之主服务器配置
我们今天来做DHCP服务器的配置,我们的前提示要实现用一台虚拟机做DHCP服务器 1.首先,我们要有DHCP软件,我们用到下面两个软件(可以使用其他方法从网上直接安装,具体方法网络搜索) dhcp-3 ...
- Install-Package 那点事儿
为了练习使用SignaR,新建了一个.net 4.0的MVC4项目, 第一步,不用说就是先将SignaR安装到项目中,考虑到SignaR 目前已经更新到2.0 并且无法在 4.0框架下面使用,此时通过 ...
- easy UI demo 含数据库加载示例
easyUI 部分代码在Googlecode 托管时而被抢此文件包含了所有官方demo,作为备份 下载地址http://pan.baidu.com/s/1pJ9hS5H
- php中的NOTICE 的错误解决方法
PHP新手NOTICE错误,特此写给那些遇到和我一样错误的朋友. 刚学习PHP,不久 最近在整留言板,刚才遇到个问题. 页面中,好多类似 Notice: in D:\wamp\www\study\ ...
- ubuntu chm文档阅读
四种方法在Ubuntu下查看CHM文件 来源:http://os.51cto.com/art/201108/287748.htm Ubuntu是一个以桌面应用为主的Linux操作系统,刚开始使用Ubu ...