SPOJ VLATTICE(莫比乌斯反演)
题意:
在一个三维空间中,已知(0,0,0)和(n,n,n),求从原点可以看见多少个点
思路:
如果要能看见,即两点之间没有点,所以gcd(a,b,c) = 1 /*来自kuangbin
利用推GCD(a,b)的方法,可以推出GCD(a,b,c) = 1的个数等于mu[i]*(n/i)*(n/i)*(n/i)的和
然而是从0点开始的,而我们只能从1开始计算,因为少了0周围的所有ans初始+3
对于A(0,0,1),所以在计算mu[i]*(n/i)*(n/i)*(n/i)时,我们忽略了A与x,y轴的求出来点的关联情况,所以加上
(n/i)*(n/i),而且有3个点所以每次要加上3*(n/i)*(n/i).
/*纯属个人理解- -
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <queue>
- #include <vector>
- #include <algorithm>
- #include <functional>
- typedef long long ll;
- using namespace std;
- const int inf = 0x3f3f3f3f;
- const int maxn = 1000000+10;
- int is_prime[maxn];
- int prime[maxn];
- int sum[maxn];
- int mu[maxn];
- int tot;
- int a,b,c,d,k;
- ll Min(ll x,ll y)
- {
- if(x < y) return x;
- else return y;
- }
- void Moblus()
- {
- tot = 0;
- memset(is_prime,0,sizeof(is_prime));
- mu[1] = 1;
- for(int i = 2; i <= maxn; i++)
- {
- if(!is_prime[i])
- {
- prime[tot++] = i;
- mu[i] = -1;
- }
- for(int j = 0; j < tot; j++)
- {
- if(prime[j]*i>maxn)
- break;
- is_prime[i*prime[j]] = 1;
- if(i % prime[j]) //prime[j]不重复
- {
- mu[i*prime[j]] = -mu[i];
- }
- else
- {
- mu[i*prime[j]] = 0;
- break;
- }
- }
- }
- }
- int main()
- {
- int T,n;
- Moblus();
- scanf("%d",&T);
- while(T--)
- {
- scanf("%d",&n);
- ll ans = 3;
- for(int i = 1;i <= n;i++)
- ans += (ll)mu[i]*((ll)(n/i)*(n/i)*(n/i) + (ll)(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 ...
随机推荐
- 坑爹了多少年的html元素垂直居中问题
原文章:https://www.w3cplus.com/css3/a-guide-to-flexbox.html 如果你的元素有固定高度的话 父元素用display: flex;height:100p ...
- Python内置函数(7)——sum
英文文档: sum(iterable[, start]) Sums start and the items of an iterable from left to right and returns ...
- React Native学习(九)—— 使用Flexbox布局
本文基于React Native 0.52 Demo上传到Git了,有需要可以看看,写了新内容会上传的.Git地址 https://github.com/gingerJY/React-Native-D ...
- SpringBoot的配置文件加载顺序和使用方式
1.bootstrap.properties bootstrap.properties 配置文件是由"根"上下文优先加载,程序启动之初就感知 如:Spring Cloud Conf ...
- Homebrew update error not work on OSX
brew update 错误是这样的 chown: /usr/local: Operation not permitted 然后网上osx 10.11, 10.12的解决方法这样的 The probl ...
- [BZOJ4011][HNOI2015] 落忆枫音(学习笔记) - 拓扑+DP
其实就是贴一下防止自己忘了,毕竟看了题解才做出来 Orz PoPoQQQ 原文链接 Description 背景太长了 给定一个DAG,和一对点(x, y), 在DAG中由x到y连一条有向边,求生成树 ...
- hdu 1880 魔咒字典
https://vjudge.net/problem/HDU-1880 题意:略 思路: 一开始就是想到了正确的思路,但是代码写炸了,死活过不了.这题嘛,就是建议一个魔咒与咒语的双向映射.首先用字符串 ...
- Django(博客系统):基于pycharm如何一个django工程下创建多个app
背景:通常我们创建一个django系统时,为了把业务模块划分清楚往往会把一个独立的业务模块放到一个app中,如果多个独立的业务模块就会创建多个app,一般情况下为了更好的管理这些app,会把他们都存放 ...
- Spark:性能调优
来自:http://blog.csdn.net/u012102306/article/details/51637366 资源参数调优 了解完了Spark作业运行的基本原理之后,对资源相关的参数就容易理 ...
- Text-查找文本
from tkinter import * master=Tk() text=Text(master,width=30,height=5) text.pack() text.insert(INSERT ...