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; 的点有多少个就可以了: 比如 : 点 ...
随机推荐
- Linux快捷键总结
使用Linux很久了,现对经常用到的快捷键做一个总结: 最重要的一个当然是tab了 [root@localhost ~]# cd /etc/sys sysconfig/ sysctl.conf sys ...
- Django中views笔记
reverse反解析 #路由中定义namespace.name,reverse可将其转换为url url = reverse('namespace:name') return redirect(url ...
- vs问题--------------标记为系统必备组建...
问题:标记为系统必备组建 要将程序集“D:\project\DMS\DMSGaeaService\TmsApplication\bin\Debug\Jns.Gaea.dll”标记为系统必备组件,必须对 ...
- Spring源码学习(7)——AOP
我们知道,使用面对对象编程的时候有一些弊端,当需要为多个不具有继承关系的对象引入同一个公共行为时,例如日志.安全检测等,所以就有了一个对面对对象编程的补充,即面对切面编程(AOP),AOP所关注的方向 ...
- Spring动态获取已注入的对象的方法
1.根据类获取对象 @Autowired ApplicationContext context; GenericMapper<T,String> dao=(GenericMapper< ...
- JavaScript 中的常用12种循环遍历(数组或对象)的方法
1.for 循环 let arr = [1,2,3]; for (let i=0; i<arr.length; i++){ console.log(i,arr[i]) } // 0 1 // 1 ...
- SQL Server DDL
1:向表中添加字段 Alter table [表名] add [列名] 类型 2: 删除字段 Alter table [表名] drop column [列名] 3: 修改表中字段类型 (可以修 ...
- Breadth-first search
given a graph G and a distinguished source vertex s, breadth-firstsearch systematically explores th ...
- B-食物链-经典并查集
动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C吃A. 现有N个动物,以1-N编号.每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种. 有人用两种 ...
- Spring 注入集合
Spring 中,注入集合类型的数值方式 <bean id="javaCollection" class="com.qie_zi.JavaCollection&qu ...