SPOJ VLATTICE (莫比乌斯反演)
传送门:https://www.spoj.com/problems/VLATTICE/en/
题意:
在三维坐标系下,你在点(0,0,0),看的范围是(n,n,n)以内,求你可以看见多少个点没有被遮挡
题解:
一条线上的点肯定是会被挡的
所以我们求的是\(gcd(x,y,z)==1\)的组数
我们设
F(d):d|gcd(x,y,z)的对数\\
由于F(d)为[n/d]*[n/d]*[n/d]\\
所以反演可得\\
f(1)=mu[d]*[n/d]*[n/d]*[n/d]\\
由于坐标系上的点也要算的话\\
1.我们的点(0,0,1)、(1,0,1)、(0,1,1)\\
2.xoy,xoz,xoy面上的点gcd(i,j)==1; \\
3.其他点 gcd(i,j,k)==1
\]
代码:
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef long long ll;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3f;
int mu[maxn];
int prime[maxn];
int not_prime[maxn];
int tot;
void Mobiwus(int n) {
    mu[1] = 1;
    for(int i = 2; i <= n; i++) {
        if(!not_prime[i]) {
            prime[++tot] = i;
            mu[i] = -1;
        }
        for(int j = 1; prime[j]*i <= n; j++) {
            not_prime[prime[j]*i] = 1;
            if(i % prime[j] == 0) {
                mu[prime[j]*i] = 0;
                break;
            }
            mu[prime[j]*i] = -mu[i];
        }
    }
}
int main() {
#ifndef ONLINE_JUDGE
    FIN
#endif
    int T;
    Mobiwus(1000005);
    scanf("%d", &T);
    while(T--) {
        int n;
        scanf("%d", &n);
        LL ans = 3;
        for(int i = 1; i <= n; i++) {
            ans += 1LL * mu[i] * (n / i) * (n / i) * (n / i);
        }
        for(int i = 1; i <= n; i++) {
            ans += 1LL * mu[i] * (n / i) * (n / i) * 3;
        }
        printf("%lld\n", ans);
    }
    return 0;
}
SPOJ VLATTICE (莫比乌斯反演)的更多相关文章
- SPOJ - VLATTICE (莫比乌斯反演)
		Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many latt ... 
- SPOJ PGCD(莫比乌斯反演)
		传送门:Primes in GCD Table 题意:给定两个数和,其中,,求为质数的有多少对?其中和的范围是. 分析:这题不能枚举质数来进行莫比乌斯反演,得预处理出∑υ(n/p)(n%p==0). ... 
- bzoj 2820 / SPOJ PGCD 莫比乌斯反演
		那啥bzoj2818也是一样的,突然想起来好像拿来当周赛的练习题过,用欧拉函数写掉的. 求$(i,j)=prime$对数 \begin{eqnarray*}\sum_{i=1}^{n}\sum_{j= ... 
- SPOJ 7001(莫比乌斯反演)
		传送门:Visible Lattice Points 题意:0<=x,y,z<=n,求有多少对xyz满足gcd(x,y,z)=1. 设f(d) = GCD(a,b,c) = d的种类数 : ... 
- SPOJ 7001 VLATTICE - Visible Lattice Points(莫比乌斯反演)
		题目链接:http://www.spoj.com/problems/VLATTICE/ 题意:求gcd(a, b, c) = 1 a,b,c <=N 的对数. 思路:我们令函数g(x)为g ... 
- 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 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 VLATTICE  Visible Lattice Points 莫比乌斯反演
		这样的点分成三类 1 不含0,要求三个数的最大公约数为1 2 含一个0,两个非零数互质 3 含两个0,这样的数只有三个,可以讨论 针对 1情况 定义f[n]为所有满足三个数最大公约数为n的三元组数量 ... 
- SPOJ VLATTICE Visible Lattice Points(莫比乌斯反演)题解
		题意: 有一个\(n*n*n\)的三维直角坐标空间,问从\((0,0,0)\)看能看到几个点. 思路: 按题意研究一下就会发现题目所求为. \[(\sum_{i=1}^n\sum_{j=1}^n\su ... 
随机推荐
- 洛谷2387 BZOJ3669魔法森林题解
			题目链接 BZ链接 这道题被很多人用spfa水了过去,表示很... 其实spfa很好卡,这组数据可以卡掉大多数spfa 链接:密码:rjvk 这里讲一下LCT的做法 我们按照a将边排序,然后依次添加 ... 
- @codeforces - 1161F@ Zigzag Game
			目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 2n 个结点的完全二分图,1~n 在左边,n+1~2n ... 
- icheck的使用
			一.什么是icheck 就是用来美化单选框.复选框的. 二.如何使用 1.下载 到 github 下载.https://github.com/fronteed/icheck 下载完毕.解压.目录结构如 ... 
- AbstractExecutorService的submit方法概要介绍
			1.概述 ExecutorService是JDK提供的框架,它简化了异步模式下的任务执行.一般来说,ExecutorService会自动提供一个线程池和API,用于为其分配任务. 2.实例化Execu ... 
- jmter正则表达式提取器
			1.若返回的body内容为空,仅有 header值,则: \s代表为空 2.使用Debug来调试 
- Part17—触摸屏显身手—Part17.1—原理简介
- Libev源码分析04:Libev中的相对时间定时器
			Libev中的超时监视器ev_timer,就是简单的相对时间定时器,它会在给定的时间点触发超时事件,还可以在固定的时间间隔之后再次触发超时事件. 所谓的相对时间,指的是如果你注册了一个1小时的超时事件 ... 
- @codeforces - 117C@ Cycle
			目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个竞赛图(有向完全图),请找出里面的某个三元环,或者判断不 ... 
- @topcoder - SRM611D1L3@ ElephantDrinking
			目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定有一个 n*n 的平原,其中一些格子有些泉水.泉水每单位时间 ... 
- @bzoj - 4378@ [POI2015] Logistyka
			目录 @description@ @solution@ @accepted code@ @details@ @description@ 维护一个长度为 n 的序列,一开始都是 0,支持以下两种操作: ... 
