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 ...
随机推荐
- (转)dubbo design
框架设计 整体设计 图例说明: 图中左边淡蓝背景的为服务消费方使用的接口,右边淡绿色背景的为服务提供方使用的接口, 位于中轴线上的为双方都用到的接口. 图中从下至上分为十层,各层均为单向依赖,右边的黑 ...
- 再说rocketmq消息存储
两篇精彩的文章: <RocketMQ源码 — 三. Producer消息发送过程> <RocketMQ源码解析:Message存储> rocketmq通过netty获取到消息请 ...
- swift基础语法之控件使用02
//第一个控制器:显示基础控件 import UIKit class ViewController: UIViewController { var label: UILabel = UILabel() ...
- TestNG测试报告美化
因TestNG自带的测试报告不太美观,可以使用testng-xslt进行美化 1.下载testng-xslt包 2.把/src/main/resources/TestNG-results.xsl放到你 ...
- Swing的GUI组件得到焦点
Swing的GUI组件如JButtin,JTextArea,JRadioButton,JComboBox等,可以使用requestFocus()方法来获得焦点.
- Win7无法安装Flash Player怎么办
在IE的工具选项中把安全选项中的ActiveX控件一系列都改为启用即可.
- Hibernate开发环境搭建
一.下载Hibernate包的下载 官网地址:http://hibernate.org/orm/ 下载版本:hibernate-release-4.3.11.Final 二.Hibernate jar ...
- mysql导入数据乱码的解决
#mysql -uroot -p -hlocalhost --default-character-set=utf8; mysql>use db_name; mysql>source /ho ...
- Android中Native和H5交互
1.概述 时至今日,H5的跨平台性越发凸显优势,一套代码适配android.ios,既能减少开发成本,又便于更新与维护.但是native的性能体验也确实更佳,尤其体现在复杂界面和频繁变化的界面上.事实 ...
- 请问大家ndk中LOCAL_SHARED_LIBRARIES LOCAL_LDLIBS什么区别
请问大家ndk中LOCAL_SHARED_LIBRARIES LOCAL_LDLIBS什么区别啊 我先是编译了一个.so 然后在此次编译的使用调用,请问用LOCAL_SHARED_LIBRARIES和 ...