SPOJ.Visible Lattice Points(莫比乌斯反演)
/*
http://www.spoj.com/problems/VLATTICE/
题意:求一个n*n*n的晶体,有多少点可以在(0,0,0)处可以直接看到。
同BZOJ.2301
题目即要求gcd(i,j,k)=1的(i,j,k)数对个数,1<=i,j,k<=n
由于是立体,所以最后再算上平面的点和坐标轴上的三个点就行了
*/
#include<cstdio>
#include<cctype>
#define gc() getchar()
typedef long long LL;
const int N=1e6+3;
int P[N+3],cnt,mu[N+3],sum[N+3];
bool Not_P[N+3];
inline int read()
{
int now=0;register char c=gc();
for(;!isdigit(c);c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now;
}
void Init()
{
mu[1]=1;
for(int i=2;i<N;++i)
{
if(!Not_P[i]) P[++cnt]=i,mu[i]=-1;
for(int j=1;j<=cnt&&i*P[j]<N;++j)
{
Not_P[i*P[j]]=1;
if(!(i%P[j])) {mu[i*P[j]]=0; break;}
mu[i*P[j]]=-mu[i];
}
}
for(int i=1;i<N;++i) sum[i]=sum[i-1]+mu[i];
}
int main()
{
Init();
int t=read(),n;
while(t--)
{
n=read();
LL ans=3;//坐标轴上的三个点
for(int nxt,i=1;i<=n;i=nxt+1)
nxt=n/(n/i), ans+=1LL*(sum[nxt]-sum[i-1])*(n/i)*(n/i)*(n/i+3);//立体空间内的和三个平面的
printf("%lld\n",ans);
}
return 0;
}
SPOJ.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 7001 Visible Lattice Points莫比乌斯反演
Visible Lattice Points Time Limit:7000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Su ...
- spoj7001 Visible Lattice Points 莫比乌斯反演+三维空间互质对数
/** 题目:Visible Lattice Points 链接:https://vjudge.net/contest/178455#problem/A 题意:一个n*n*n大小的三维空间.一侧为(0 ...
- 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 (莫比乌斯反演)
题意:求一个正方体里面,有多少个顶点可以在(0,0,0)位置直接看到,而不被其它点阻挡.也就是说有多少个(x,y,z)组合,满足gcd(x,y,z)==1或有一个0,另外的两个未知数gcd为1 定义f ...
- Spoj 7001 Visible Lattice Points 莫比乌斯,分块
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193 Visible Lattice Points Time L ...
- 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, ...
随机推荐
- adboost方法(转载)
转载链接:http://blog.csdn.net/google19890102/article/details/46376603 一.集成方法(Ensemble Method) 集成方法主要 ...
- linux统计某个特定文件名的大小总和【原创】
[hch@EAISRVBJ2 log]$find ./ -name "test_chs_00*"|xargs du -ck|grep total|awk 'BEGIN{sum=0} ...
- 005_关于HTTP协议中的保持连接
缘起 中午在群里讨论,用ab测试 一台只提供静态文件服务, 不与其他任何系统交互的时候,为什么也会产生大量的TIME WAIT状态的. 首先,我们可以简单的理解,在TCP连接的两端,谁主动断开连接(先 ...
- opencv error: insufficient memory错误解决办法
用opencv合成图像时出现的错误,大概4000多张会报错,在网上查阅一些博客时才知道原因.之前编译的时候用的是x86,切换到x64下可解决问题,具体: 1.项目->属性->配置管理器-& ...
- 【python】logging记录traceback
import logging try: do-something-block except: logging.exception("Exception Logged")
- css 文件连接不到网页
css 文件连接不到网页 编码错误,将编码改为utf-8 Rom后正常
- python+selenium九:ddt数据驱动
第一种,测试数据放在Excel里面 test_Login: import unittestimport timeimport ddtimport osfrom selenium import webd ...
- 天天爱跑步&&弹球
题解: 弹球题目地址:https://www.nowcoder.com/acm/contest/113/E 后面这题 应该是天天爱跑步的加强版本 原理都是查询子树中dep[x]+f[x]的值的个数 由 ...
- python全栈开发day24-__new__、__del__、item系列、异常处理
一.昨日内容回顾 1.反射 用字符串类型的名字,操作命名空间的变量. 反射使用场景:明显的简化代码,能拿到的变量名本来就是一个字符串类型的时候, 用户输入的,文件读入的,网上传输的 2.__call_ ...
- python全栈开发day17-常用模块collections,random,time,os,sys,序列化(json pickle shelve)
1.昨日内容回顾 1.正则表达式 # 正则表达式 —— str # 检测字符串是否符合要求 # 从大段的文字中找到符合要求的内容 1).元字符 #. # 匹配除换行 ...