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 ...
随机推荐
- Android 读取txt文件并以utf-8格式转换成字符串
博客: 安卓之家 微博: 追风917 CSDN: 蒋朋的家 简书: 追风917 博客园: 追风917 # 使用EncodingUtils 今天用到了城市选择三级联动的库,用的这个:https://gi ...
- 线程池ThreadPoolExecutor使用简介
一.简介 线程池类为 java.util.concurrent.ThreadPoolExecutor,常用构造方法为: ThreadPoolExecutor(int corePoolSize, int ...
- CSS Positioning(定位)
Positioning(定位) CSS定位属性允许你为一个元素定位.它也可以将一个元素放在另一个元素后面,并指定一个元素的内容太大时,应该发生什么. 元素可以使用的顶部,底部,左侧和右侧属性定位.然而 ...
- 【转】Spring.NET学习笔记——目录
目录 前言 Spring.NET学习笔记——前言 第一阶段:控制反转与依赖注入IoC&DI Spring.NET学习笔记1——控制反转(基础篇) Level 200 Spring.NET学习笔 ...
- struts-json
Struts2序列化的属性,该属性在action中必须有对应的getter方法 如果action的属性很多,我们想要从Action返回到调用页面的数据.这个时候配置includeProperties或 ...
- [Machine Learning] Probabilistic Graphical Models:一、Introduction and Overview(1、Overview and Motivation)
一.PGM用来做什么 1. 医学诊断:从各种病症分析病人得了什么病,该用什么手段治疗 2. 图像分割:从一张百万像素级的图片中分析每个像素点对应的是什么东西 两个共同点:(1)有非常多不同的输入变 ...
- [转] 小tips: 使用 等空格实现最小成本中文对齐 ---张鑫旭
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=4562 一.重见天日第 ...
- CANoe 入门 Step by step系列(一)基础应用【转】
CANoe是Vector公司的针对汽车电子行业的总线分析工具,现在我用CANoe7.6版本进行介绍,其他版本功能基本差不多. 硬件我使用的是CAN case XL. 1,CANoe软件的安装很简单,先 ...
- paramiko学习
1. ssh简介 2. ssh私有key/共有key的区别 3. paramiko的常规使用
- js 图片base64
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...