VLATTICE - Visible Lattice Points [Spoj 7001]
2016-06-05 11:19
344 查看
题目地址——
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 if no other lattice point lies on the segment joining X and Y.
The next T lines contain an interger N.
1
2
5
19
175
1<=N<=1000000 .
就是一个 n∗n∗n 的空间,一个人在 (0,0,0),问他能够看到几个点。
用莫比乌斯反演就很easy了。
f(d)=∑d|iμ(id)⋅⌊ni⌋2⋅(⌊ni⌋+3)ans=3+f(1)
VLATTICE - Visible Lattice Points
如果不想看英文,请点击——【题目描述】
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 if no other lattice point lies on the segment joining X and Y.
【输入描述】
The first line contains the number of test cases T.The next T lines contain an interger N.
【输出描述】
Output T lines, one corresponding to each test case.【Sample Input】
31
2
5
【Sample Output】
719
175
【Constraints】
T<=50,1<=N<=1000000 .
【Solution】
本题题意(让我来当一回翻译):就是一个 n∗n∗n 的空间,一个人在 (0,0,0),问他能够看到几个点。
用莫比乌斯反演就很easy了。
f(d)=∑d|iμ(id)⋅⌊ni⌋2⋅(⌊ni⌋+3)ans=3+f(1)
【Code】
#include <iostream> #include <cstdio> #define LL long long using namespace std; int T; LL n; short miu[1000010]; int prime[1000010]; bool no_prime[1000010]; int main(){ scanf("%d",&T); miu[1]=1; for(LL i=2;i<=1000000;i++){ if(!no_prime[i]){ prime[++prime[0]]=i; miu[i]=-1; } for(LL j=1;prime[j]*i<=1000000;j++){ no_prime[prime[j]*i]=true; if(i%prime[j]==0){ miu[prime[j]*i]=0; break; } miu[prime[j]*i]=-miu[i]; } } while(T--){ LL ans=3; scanf("%lld",&n); LL tmp=0; while(1){ tmp++; if(tmp>n)break; ans+=miu[tmp]*((n/tmp)*(n/tmp)*(n/tmp+3)); } printf("%lld\n",ans); } return 0; }
相关文章推荐
- Mybatis generator 自动生成代码时 ,insert如何返回主键值
- class文件校验器分成四趟独立的扫描来完成校验。
- xml文件解析和序列化
- 第十五周项目一 阅读下面程序,解释运行结果(6)
- Spring NoSuchBeanDefinitionException原因分析
- Linux学习之if语句
- Android学习记录(一) 重拾Activity
- MyBatis批量插入数据
- 传p还是传*p
- Intent
- 模块和作用域
- 绕过百度云的签名认证
- ie6、7 margin负值部分无法看到的解决方法
- Implement Queue using Stacks
- httpd之拒绝某些user_agent
- 高并发的网站架构
- 单源最短路HDU2544
- PHP的优点和特点
- Retrofit 2.0文件上传
- sublime text中的一些快速编辑技巧以及服务器功能