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 ...
随机推荐
- 模拟源码深入理解Vue数据驱动原理(1)
Vue有一核心就是数据驱动(Data Driven),允许我们采用简洁的模板语法来声明式的将数据渲染进DOM,且数据与DOM是绑定在一起的,这样当我们改变Vue实例的数据时,对应的DOM元素也就会改变 ...
- 解决NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
使用spring3.05 mvc进行开发,使用tomcat容器,通过url映射寻找view的时候,会报错NoClassDefFoundError: javax/servlet/jsp/jstl/cor ...
- JMS之——ActiveMQ 高可用与负载均衡集群安装、配置(ZooKeeper + LevelDB + Static discovery)
一.说明 从 ActiveMQ 5.9 开始, ActiveMQ 的集群实现方式取消了传统的 Master-Slave 方式,增加了基于ZooKeeper + LevelDB 的 Master-Sla ...
- 极客技术专题【011期】:EasyUI初级教程
来源:GBin1.com 技术专题:EasyUI初级教程 分享人:极客标签技术编辑 - html580(请站内关注分享人) 资深Web前端工程师,HTML580创始人,目前就职于广州一间软件公司.多年 ...
- Unity 3d导入3dMax模型 产生若干问题
Unity 3d导入3dMax模型 会产生若干问题,按照官方 的说明,将max 模型导成fbx文件 导入untiy似乎也不能解决 1.x轴向偏转3dmax模型导入后自动有一个x轴270度的偏转,巧合的 ...
- 单例模式的Oracle 数据库连接应用
新建一个类来实现单例模式的Oracle 数据库连接应用 组织架构如下: 类的具体代码如下: package com.zse.dba; import java.sql.*; //设计模式1:单例模式.保 ...
- swipeRefreshLayout与webview滑动冲突
遇到这么个bug,webview使用swipeRefreshLayout时,下拉时事件不会被webview捕获,而是执行swipeRefreshLayout的刷新,网上一大堆一大堆的解决办法,都是什么 ...
- html5-表单常见操作
<form autocompelate="on" id="from1"><!--常用属性-->邮件:<input type=&q ...
- jfinal的configPlugin基本配置代码
直接上代码: public void configPlugin(Plugins me) { // 这里是在数据库的配置文件中读取数据库的一些信息 DruidPlugin dbPlugin = new ...
- NGUI 取ScrollView中遮罩区域4个点
用panel.localCorners而不是panel.finalClipRegion,Region还要再换算 首先通过ScrollView取panel,然后取Corners,它返回值代表4个点,映射 ...