Visible Lattice Points SPOJ - VLATTICE 三维+莫比乌斯反演
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e7+;
int vis[maxn];
int mu[maxn];
int prime[maxn];
int tot=;
int sum1[maxn];
int sum2[maxn];
void get_mu()
{
mu[]=; vis[]=;
for(int i=;i<maxn;i++)
{
if(!vis[i]) {mu[i]=-; prime[++tot]=i; }
for(int j=;j<=tot && i*prime[j]<maxn;j++)
{
vis[i*prime[j]]=;
if(i%prime[j]==) break;
mu[i*prime[j]]=-mu[i];
}
}
for(int i=;i<maxn;i++)
sum2[i]=sum2[i-]+mu[i];
}
int main()
{
get_mu();
int T; cin>>T;
while(T--)
{
int n; cin>>n;
ll ans=;
for(int l=,r;l<=n;l=r+)
{
r=n/(n/l);
ans+=(sum2[r]-sum2[l-])*1ll*(n/l)*(n/l)*(n/l);
ans+=(sum2[r]-sum2[l-])*1ll*(n/l)*(n/l)*;
}
cout<<ans+<<endl;
}
}
Visible Lattice Points SPOJ - VLATTICE 三维+莫比乌斯反演的更多相关文章
- SPOJ VLATTICE (莫比乌斯反演)
传送门:https://www.spoj.com/problems/VLATTICE/en/ 题意: 在三维坐标系下,你在点(0,0,0),看的范围是(n,n,n)以内,求你可以看见多少个点没有被遮挡 ...
- SPOJ VLATTICE(莫比乌斯反演)
题意: 在一个三维空间中,已知(0,0,0)和(n,n,n),求从原点可以看见多少个点 思路: 如果要能看见,即两点之间没有点,所以gcd(a,b,c) = 1 /*来自kuangbi ...
- 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 数论 莫比乌斯反演
7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0, ...
- 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 7001 Visible Lattice Points莫比乌斯反演
Visible Lattice Points Time Limit:7000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Su ...
- Spoj 7001 Visible Lattice Points 莫比乌斯,分块
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193 Visible Lattice Points Time L ...
- Visible Lattice Points (莫比乌斯反演)
Visible Lattice Points 题意 : 从(0,0,0)出发在(N,N,N)范围内有多少条不从重合的直线:我们只要求gcd(x,y,z) = 1; 的点有多少个就可以了: 比如 : 点 ...
随机推荐
- 002dayPython学习编码
由于计算机是美国人发明的,所以计算机最开始只能识别256个字符(ASCII码),而你在计算机中输入中文就会报错 而中国人想让计算机认识中文,就重新编写了一套支持中文的编码(GB2312) 随后由于GB ...
- Android 访问地址
private String url_data = "https://api.douban.com/v2/movie/top250?start=0&count=10"; 免 ...
- HTML中data-* 属性
使用 data-* 属性来嵌入自定义数据: <ul><li data-animal-type="bird">Owl</li><li dat ...
- web前端的前景
随着时代的发展,现在从事IT方向的人有很多,所以励志要成为前端开发工程师的人有很多.当然也有很多人在犹豫不知道该从事哪个方向,我今天就是来给大家分析一下Web前端开发的前景.包括工作内容,发展前景和薪 ...
- 【转】Android-Input 触摸设备
https://source.android.com/devices/input/touch-devices 触摸设备 Android 支持各种触摸屏和触摸板,包括基于触控笔的数字化板. 触摸屏是与显 ...
- Python02(Linux命令)
Trainning-day01回顾 1.who :查看登录到系统的用户信息 2.pwd :查看当前所在路径 3.ls :查看当前目录的内容 ls -l ls -a ls -la / ls -l -a ...
- Python matplotlib绘图学习笔记
测试环境: Jupyter QtConsole 4.2.1Python 3.6.1 1. 基本画线: 以下得出红蓝绿三色的点 import numpy as npimport matplotlib. ...
- vue添加页面键盘事件
我司开发项目,用的是vue+elementUI,做登陆页面的时候,点击enter键的时候要实现和点击登陆按钮一样的功能,所以就百度了一下,于是一通百度之后,就在点击按钮上面直接添加了@keyup.en ...
- Matlab_ eval 批量定义变量
本文备忘 Matlab 中批量定义变量的方法. 参考: [1] matlab中批量赋值与声明变量(eval函数) [2] MathWorks eval 缘起与说明 当变量名称多到一定程度时,变量名的管 ...
- Matlab R2015b_@Ubuntu 16_安装备忘
1.下载解压包解压 2.cd 进入文件夹,使用 sh 打开,安装过程中不要使用“网络激活” 3.mv Crack文件中的 /R2015b/bin/glnxa64 里面的三个lib*.so 到Matla ...