spoj7001 Visible Lattice Points 莫比乌斯反演+三维空间互质对数
/**
题目:Visible Lattice Points
链接:https://vjudge.net/contest/178455#problem/A
题意:一个n*n*n大小的三维空间。一侧为(0,0,0)另一侧为(n,n,n);
问从(0,0,0)出发的经过该范围三维空间内整数点坐标的射线有多少条。 思路:
类比二维的:求1<=x<=n,1<=y<=n; gcd(x,y)=1的对数。因为y/x,所以可以反过来。
三维的:求1<=x,y,z<=n; gcd(x,y,z)=1的对数。 定义:
f(n) 表示gcd(x,y,z)=n的对数。 F(n) 表示n|gcd(x,y,z)的对数。 f(n) = sigma(mu[d/n]*F(d)) (n|d) f(1) = sigma(mu[d]*F(d)) (1|d); F(n) = (x/n)*(y/n)*(z/n); 由于坐标存在0的情况。当x,y,z两个为0时候,就是坐标轴,三个坐标轴贡献为3;
当x,y,z一个为0的时候,有三个面。为二维的。每一面求一下二维的互质对数[1,n]中gcd(x,y)=1的对数。 ans = 三维对数+3个二维对数+三个坐标轴。 */
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
#define ms(x,y) memset(x,y,sizeof x)
typedef pair<int, int> P;
const LL INF = 1e10;
const int mod = 1e9 + ;
const int maxn = 1e6 + ;
int prime[maxn], tot, not_prime[maxn];
int mu[maxn], sum[maxn];
void init()
{
mu[] = ;
tot = ;
for(int i = ; i < maxn; i++){
if(!not_prime[i]){
prime[++tot] = i;
mu[i] = -;
}
for(int j = ; prime[j]*i<maxn; j++){
not_prime[prime[j]*i] = ;
if(i%prime[j]==){
mu[prime[j]*i] = ;
break;
}
mu[prime[j]*i] = -mu[i];
}
}
for(int i = ; i < maxn; i++) sum[i] = sum[i-]+mu[i];
}
LL solve2(int n)///x在[1,n],y在[1,n]。求gcd(x,y)=1的对数.
{
LL ans = ;
int last;
for(int i = ; i <= n; i=last+){
last = n/(n/i);
ans += (LL)(sum[last]-sum[i-])*(n/i)*(n/i);
}
return ans;
}
LL solve(int n)///x在[1,n], y在[1,n],z在[1,n] gcd(x,y,z)=1的对数。
{
LL ans = ;
int last;
for(int i = ; i <= n; i=last+){
last = n/(n/i);
ans += (LL)(sum[last]-sum[i-])*(n/i)*(n/i)*(n/i);
}
return ans;
}
int main()
{
//freopen("in.txt","r",stdin);
int T;
int n;
init();
cin>>T;
while(T--)
{
scanf("%d",&n);
printf("%lld\n",solve(n)++*solve2(n));
}
return ;
}
spoj7001 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 ...
- 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 (莫比乌斯反演)
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 ...
随机推荐
- 从项目上一个子查询扩展学习开来:mysql的查询、子查询及连接查询
上面这样的数据,想要的结果是:如果matchResult为2的话,代表是黑名单.同一个softId,version,pcInfoId的代表是同一个软件,需要去重:同时,如果相同软件里面只要有一个mat ...
- linux(虚拟机中)与windows共享文件两种方法
Windows 下用 SourceInsight 与 Linux 协作编码 习惯了用SourceInsight 读写代码,在Linux下一时没找到类似的工具,vi的操作也不熟,偶尔看看或小 ...
- C# 调用 Web Service 时出现 : 407 Proxy Authentication Required错误的解决办法
// 记得 using System.Net; System.Net.WebProxy myProxy = new System.Net.WebProxy("localhost:9099&q ...
- C中strstr的实现方法
做题目的时候须要自己实现strstr函数 /************************************************************************/ /* 编 ...
- PHP上传文件类 代码练习
类文件: <?php class upload{ protected $fileName; protected $uploadPath; protected $maxSize; protecte ...
- ASP.NET WEB API处理流程
前言:大图请看 http://www.asp.net/posters/web-api/ASP.NET-Web-API-Poster.pdf Web Api Hosting 我们不仅可以通过Web应用程 ...
- Unity3d 录像
flashtd1: 回复 tqfa :我觉得是有方法可以实现的,之前使用高通的增强显示开发包时发现其实它是添加了一个类似movietexture的东西,叠加在它的摄像机上 如果文档里有操作moviet ...
- ant 重置(修改)DatePicker MonthPicker Cascader 的值
1.清空值 this.props.form.resetFields(); 2.监听 props 的变化,触发 清空按钮 .
- js foreach函数 注意事项(break、continue)
foreach API说明: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Arra ...
- python贪吃蛇
代码地址如下:http://www.demodashi.com/demo/13335.html 一.先展示python贪吃蛇效果 二.操作说明 按键 功能 UP 向上移动 DOWN 向下移动 LEFT ...