题意:

在一个三维空间中,已知(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).
  /*纯属个人理解- -

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <queue>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <functional>
  9. typedef long long ll;
  10. using namespace std;
  11. const int inf = 0x3f3f3f3f;
  12. const int maxn = 1000000+10;
  13.  
  14. int is_prime[maxn];
  15. int prime[maxn];
  16. int sum[maxn];
  17. int mu[maxn];
  18. int tot;
  19.  
  20. int a,b,c,d,k;
  21. ll Min(ll x,ll y)
  22. {
  23. if(x < y) return x;
  24. else return y;
  25. }
  26. void Moblus()
  27. {
  28. tot = 0;
  29. memset(is_prime,0,sizeof(is_prime));
  30. mu[1] = 1;
  31. for(int i = 2; i <= maxn; i++)
  32. {
  33. if(!is_prime[i])
  34. {
  35. prime[tot++] = i;
  36. mu[i] = -1;
  37. }
  38.  
  39. for(int j = 0; j < tot; j++)
  40. {
  41. if(prime[j]*i>maxn)
  42. break;
  43. is_prime[i*prime[j]] = 1;
  44. if(i % prime[j]) //prime[j]不重复
  45. {
  46. mu[i*prime[j]] = -mu[i];
  47. }
  48. else
  49. {
  50. mu[i*prime[j]] = 0;
  51. break;
  52. }
  53. }
  54. }
  55. }
  56.  
  57. int main()
  58. {
  59. int T,n;
  60. Moblus();
  61. scanf("%d",&T);
  62. while(T--)
  63. {
  64. scanf("%d",&n);
  65. ll ans = 3;
  66. for(int i = 1;i <= n;i++)
  67. ans += (ll)mu[i]*((ll)(n/i)*(n/i)*(n/i) + (ll)(n/i)*(n/i)*3);
  68. printf("%lld\n",ans);
  69. }
  70. return 0;
  71. }

  

SPOJ VLATTICE(莫比乌斯反演)的更多相关文章

  1. 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 ...

  2. SPOJ PGCD(莫比乌斯反演)

    传送门:Primes in GCD Table 题意:给定两个数和,其中,,求为质数的有多少对?其中和的范围是. 分析:这题不能枚举质数来进行莫比乌斯反演,得预处理出∑υ(n/p)(n%p==0). ...

  3. bzoj 2820 / SPOJ PGCD 莫比乌斯反演

    那啥bzoj2818也是一样的,突然想起来好像拿来当周赛的练习题过,用欧拉函数写掉的. 求$(i,j)=prime$对数 \begin{eqnarray*}\sum_{i=1}^{n}\sum_{j= ...

  4. SPOJ 7001(莫比乌斯反演)

    传送门:Visible Lattice Points 题意:0<=x,y,z<=n,求有多少对xyz满足gcd(x,y,z)=1. 设f(d) = GCD(a,b,c) = d的种类数 : ...

  5. SPOJ 7001 VLATTICE - Visible Lattice Points(莫比乌斯反演)

    题目链接:http://www.spoj.com/problems/VLATTICE/ 题意:求gcd(a, b, c) = 1    a,b,c <=N 的对数. 思路:我们令函数g(x)为g ...

  6. 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 ...

  7. 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 ...

  8. [SPOJ VLATTICE]Visible Lattice Points 数论 莫比乌斯反演

    7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0, ...

  9. SPOJ VLATTICE Visible Lattice Points 莫比乌斯反演

    这样的点分成三类 1 不含0,要求三个数的最大公约数为1 2 含一个0,两个非零数互质 3 含两个0,这样的数只有三个,可以讨论 针对 1情况 定义f[n]为所有满足三个数最大公约数为n的三元组数量 ...

  10. SPOJ VLATTICE Visible Lattice Points(莫比乌斯反演)题解

    题意: 有一个\(n*n*n\)的三维直角坐标空间,问从\((0,0,0)\)看能看到几个点. 思路: 按题意研究一下就会发现题目所求为. \[(\sum_{i=1}^n\sum_{j=1}^n\su ...

随机推荐

  1. 坑爹了多少年的html元素垂直居中问题

    原文章:https://www.w3cplus.com/css3/a-guide-to-flexbox.html 如果你的元素有固定高度的话 父元素用display: flex;height:100p ...

  2. Python内置函数(7)——sum

    英文文档: sum(iterable[, start]) Sums start and the items of an iterable from left to right and returns ...

  3. React Native学习(九)—— 使用Flexbox布局

    本文基于React Native 0.52 Demo上传到Git了,有需要可以看看,写了新内容会上传的.Git地址 https://github.com/gingerJY/React-Native-D ...

  4. SpringBoot的配置文件加载顺序和使用方式

    1.bootstrap.properties bootstrap.properties 配置文件是由"根"上下文优先加载,程序启动之初就感知 如:Spring Cloud Conf ...

  5. Homebrew update error not work on OSX

    brew update 错误是这样的 chown: /usr/local: Operation not permitted 然后网上osx 10.11, 10.12的解决方法这样的 The probl ...

  6. [BZOJ4011][HNOI2015] 落忆枫音(学习笔记) - 拓扑+DP

    其实就是贴一下防止自己忘了,毕竟看了题解才做出来 Orz PoPoQQQ 原文链接 Description 背景太长了 给定一个DAG,和一对点(x, y), 在DAG中由x到y连一条有向边,求生成树 ...

  7. hdu 1880 魔咒字典

    https://vjudge.net/problem/HDU-1880 题意:略 思路: 一开始就是想到了正确的思路,但是代码写炸了,死活过不了.这题嘛,就是建议一个魔咒与咒语的双向映射.首先用字符串 ...

  8. Django(博客系统):基于pycharm如何一个django工程下创建多个app

    背景:通常我们创建一个django系统时,为了把业务模块划分清楚往往会把一个独立的业务模块放到一个app中,如果多个独立的业务模块就会创建多个app,一般情况下为了更好的管理这些app,会把他们都存放 ...

  9. Spark:性能调优

    来自:http://blog.csdn.net/u012102306/article/details/51637366 资源参数调优 了解完了Spark作业运行的基本原理之后,对资源相关的参数就容易理 ...

  10. Text-查找文本

    from tkinter import * master=Tk() text=Text(master,width=30,height=5) text.pack() text.insert(INSERT ...