Visible Lattice Points (莫比乌斯反演)
Visible Lattice Points
题意 : 从(0,0,0)出发在(N,N,N)范围内有多少条不从重合的直线;我们只要求gcd(x,y,z) = 1; 的点有多少个就可以了;
比如 : 点(2,4,6)可以等价成(1,2,3)即经过(1,2,3)的线一定经过(2,4,6);
莫比乌斯反演的模板题, 由于点坐标可以为0 , 需要考虑 x, y, z 中两个为0 和一个为0 的情况 :
两个为0 时 : 有 三个点(在x , y, z 轴上); 一个为0 时 : mu[i] * (n/i) * (n/i) * 3;
即 : mu[i] * (n/i) * (n/i)* (n/i+3) + 3;
#include<iostream>
#include<cstring> using namespace std;
#define ll long long
const int maxn = ; ll mu[maxn], pri[maxn], T, cnt, vis[maxn]; void init()
{
memset(vis, , sizeof(vis));
memset(mu,,sizeof(mu));
mu[] = ;
cnt = ;
ll n = ;
for(ll i = ; i <= n; i++)
{
if(!vis[i])
{
mu[i] = -;
pri[cnt++] = i;
}
for(ll j = ; j < cnt&&i*pri[j] <= n; j++)
{
ll k = i*pri[j];
vis[k] = ;
if(i%pri[j] == ) {mu[k] = ; break;}
else mu[k] = -mu[i];
}
}
} int main()
{
// ios::sync_with_stdio(false); init();
cin >> T;
while(T--)
{
ll n;
cin >> n;
ll ans = ;
for(ll i = ; i <= n; i++)
ans += (ll)(mu[i] * (n/i) * (n/i)* (n/i+));
cout << ans << endl; }
return ; }
Visible Lattice Points (莫比乌斯反演)的更多相关文章
- 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 ...
- spoj7001 Visible Lattice Points 莫比乌斯反演+三维空间互质对数
/** 题目:Visible Lattice Points 链接:https://vjudge.net/contest/178455#problem/A 题意:一个n*n*n大小的三维空间.一侧为(0 ...
- spoj 7001 Visible Lattice Points莫比乌斯反演
Visible Lattice Points Time Limit:7000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Su ...
- SPOJ VLATTICE Visible Lattice Points 莫比乌斯反演
这样的点分成三类 1 不含0,要求三个数的最大公约数为1 2 含一个0,两个非零数互质 3 含两个0,这样的数只有三个,可以讨论 针对 1情况 定义f[n]为所有满足三个数最大公约数为n的三元组数量 ...
- 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 7001 Visible Lattice Points (莫比乌斯反演)
题意:求一个正方体里面,有多少个顶点可以在(0,0,0)位置直接看到,而不被其它点阻挡.也就是说有多少个(x,y,z)组合,满足gcd(x,y,z)==1或有一个0,另外的两个未知数gcd为1 定义f ...
- SPOJ.Visible Lattice Points(莫比乌斯反演)
题目链接 /* http://www.spoj.com/problems/VLATTICE/ 题意:求一个n*n*n的晶体,有多少点可以在(0,0,0)处可以直接看到. 同BZOJ.2301 题目即要 ...
- Spoj 7001 Visible Lattice Points 莫比乌斯,分块
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193 Visible Lattice Points Time L ...
- spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演
SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...
随机推荐
- ORACLE INSTANCE与EM系统
Emctl start dbconsole https://192.168.183.132:1158/em/ 复制到游览器进入到em 更改初始化参数值 静态参数: -只能在参数文件中更改 -必须重新启 ...
- DDL触发器(用来控制用户的DDL行为)
DDL触发器 禁止scott用户的所有DDL操作 create or replace trigger scott_forbid_trigger before ddl on schema begin r ...
- python之文件操作示例
方法一: with open("e:\\gloryroad.txt","a+",encoding="utf-8") as file: fil ...
- Vue子组件调用父组件的方法
Vue子组件调用父组件的方法 Vue中子组件调用父组件的方法,这里有三种方法提供参考 第一种方法是直接在子组件中通过this.$parent.event来调用父组件的方法 父组件 <temp ...
- Orchard Core 版本冲突 The type 'FormTagHelper' exists in both 'Microsoft.AspNetCore.Mvc.TagHelpers, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' and...
最近老大让我看Orchard Core,这是一个CMS系统.可以先参考大佬的文章:https://www.cnblogs.com/shanyou/archive/2018/09/25/9700422. ...
- localstorage 和 sessionstorage 是什么?区别是什么?
localstorage 和 sessionstorage 一样都是用来存储客户端临时信息的对象,他们均只能存储字符串类型对象: localstorage生命周期是永久的,这意味着除非用户在浏览器提供 ...
- 关于flexjson将json转为javabean的使用
关于flexjson将json转为javabean的使用 import java.sql.Timestamp; import java.util.Date; import flexjson.JSOND ...
- logback logback.xml常用配置详解(二)<appender>
转自:http://aub.iteye.com/blog/1101260 logback 常用配置详解(二) <appender> <appender>: <append ...
- Linux查看访问IP
Linux查看访问IP https://blog.csdn.net/tojohnonly/article/details/82772323
- linux网络设置和虚拟机克隆转移之后网卡找不到
linux网络设置和虚拟机克隆转移之后Error:No suitable device found:no device found for connection 'System eth0'问题解决 ...