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; 的点有多少个就可以了: 比如 : 点 ...
随机推荐
- Oracle 11g 测试ogg中断之后,重新同步操作
测试ogg中断之后,重新同步操作 2018-06-07 17:11 779 1 原创 GoldenGate 本文链接:https://www.cndba.cn/leo1990/article/2839 ...
- github同一账户+多个库
目标 我的情况是,既要向自己的public库提交代码,又要向别人的private库提交代码 网上搜到的情况一:github上有多个账号,都要向自己的库提交代码 网上搜到的情况二:多个git托管源(比如 ...
- java-js知识库之二——canvas绘制炫彩气泡
现在使用canvas绘制气泡,虽说很多人都已经实现过了,可能方法都大同小异,但自己写和看别人写完全是两码事,自己会写的才是自己的,话不多说,直接上代码. 先来一张效果图: 现在上代码,代码有详细的注释 ...
- mysql的简单安装方法
准备工作MySQL-Front与mysql-5.5.15-win32 开始安装 选择compelete,完整安装 自动弹出配置界面 选择标准配置 设置root密码 成功界面 MySQL-Front 的 ...
- Windows下PyMC安装
先安装Anaconda2 然后conda install -c https://conda.binstar.org/pymc pymc
- php字符串转数组
下面代码包括了含有中文汉字的字符. function str2arr($str) { $length = mb_strlen($str, 'utf-8'); $array = []; for ($i= ...
- python 面试题之 生成器
如下函数执行结果是什么? 答案: [20, 21, 22, 23] 核心要点:本题重点在对生成器的理解, 生成器具有惰性机制 ,只有在取值的时候才执行. 解析: for 循环遍历列表,执行了两次 第 ...
- Shell 函数相关
一.函数的两种定义方式 第一种:函数名(){ ...... } 第二种:function 函数名{ ...... } 调用时直接使用 函数名 调用,将函数当作一个“命令”即可.函数内部直接使用 $1. ...
- django遇到的问题-系列1
django开发中遇到的问题以及解决方法: 1.You called this URL via POST, but the URL doesn't end in a slash and you hav ...
- Python3.x - 字符串
Python3 字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号( ' 或 " )来创建字符串. var1 = 'hello world' var2 = "he ...