这样的点分成三类

1 不含0,要求三个数的最大公约数为1

2 含一个0,两个非零数互质

3 含两个0,这样的数只有三个,可以讨论

针对 1情况 定义f[n]为所有满足三个数最大公约数为n的三元组数量

F[n]为所有满足三个数的最大公约数能被n整除的三元组数量

显然 F[n]=∑n|df[d]

然后由莫比乌斯反演,f[n]=∑n|dμ[d/n]*F[d]

情况三也是一样的

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<set>
  4. #include<vector>
  5. #include<queue>
  6. #include<cstdlib>
  7. #include<cstdio>
  8. #include<cstring>
  9. #include<cmath>
  10. using namespace std;
  11. typedef long long LL;
  12. typedef unsigned long long ULL;
  13. const int N=1e6+;
  14. int n,T,prime[N],mu[N];
  15. bool vis[N];
  16. void getmu()
  17. {
  18. mu[] = ;
  19. int cnt = ;
  20. for(int i=; i<=N-; i++)
  21. {
  22. if(!vis[i])
  23. {
  24. prime[cnt++] = i;
  25. mu[i] = -;
  26. }
  27. for(int j=; j<cnt&&i*prime[j]<=N-; j++)
  28. {
  29. vis[i*prime[j]] = ;
  30. if(i%prime[j]) mu[i*prime[j]] = -mu[i];
  31. else
  32. {
  33. mu[i*prime[j]] = ;
  34. break;
  35. }
  36. }
  37. }
  38. }
  39. LL F1(LL x){
  40. x=n/x;
  41. return x*x*x;
  42. }
  43. LL F2(LL x){
  44. x=n/x;
  45. return x*x*;
  46. }
  47. int main(){
  48. getmu();
  49. scanf("%d",&T);
  50. while(T--){
  51. scanf("%d",&n);
  52. LL ans=;
  53. for(int i=;i<=n;++i){
  54. ans+=mu[i]*F1(i);
  55. ans+=mu[i]*F2(i);
  56. }
  57. printf("%lld\n",ans+);
  58. }
  59. return ;
  60. }

SPOJ VLATTICE Visible Lattice Points 莫比乌斯反演的更多相关文章

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

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

  3. spoj 7001 Visible Lattice Points莫比乌斯反演

    Visible Lattice Points Time Limit:7000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Su ...

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

    题意:求一个正方体里面,有多少个顶点可以在(0,0,0)位置直接看到,而不被其它点阻挡.也就是说有多少个(x,y,z)组合,满足gcd(x,y,z)==1或有一个0,另外的两个未知数gcd为1 定义f ...

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

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

  6. Spoj 7001 Visible Lattice Points 莫比乌斯,分块

    题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193   Visible Lattice Points Time L ...

  7. spoj7001 Visible Lattice Points 莫比乌斯反演+三维空间互质对数

    /** 题目:Visible Lattice Points 链接:https://vjudge.net/contest/178455#problem/A 题意:一个n*n*n大小的三维空间.一侧为(0 ...

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

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

  9. SPOJ VLATTICE - Visible Lattice Points 【“小”大数加减】

    题目链接 一道比较简单的莫比乌斯反演,不过ans会爆long long,我是用结构体来存结果的,结构体中两个LL型变量分别存大于1e17和小于1e17的部分 #include<bits/stdc ...

随机推荐

  1. HaProxy+keepalived实现负载均衡

    HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持 ...

  2. 解决VS2008打开假死或者打开设计模式假死的问题

    我昨天刚装完OFFICE 2010一直也没重启,vs2008是可以使用的.今早来到办公室,打开工程发现开了半天VS2008一般空白,查看应用程序显示正在运行,再查看进程发现里面多一个setup.exe ...

  3. Cassandra1.2文档学习(7)—— 规划集群部署

    数据参考:http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/architecture/a ...

  4. 003.XE3包含了TPerlRegEx的单元

    使用'|'替换所有的内容 代码: program Project1; {$APPTYPE CONSOLE} uses System.SysUtils, System.RegularExpression ...

  5. Python 爬虫入门(requests)

    相信最开始接触Python爬虫学习的同学最初大多使用的是urllib,urllib2.在那之后接触到了第三方库requests,requests完全能满足各种http功能,真的是好用爆了 :D 他们是 ...

  6. php中一些安全性防止问题建议

    只要我们作好了各类操作就可在基本防止一些朋友利用网站本身的漏洞进行网站操作了,很多在php中都有的如XSS用 htmlentities()预防XSS攻击还有sql注入可以用mysql_real_esc ...

  7. 什么是UI控件

    凡是带有Widget参数的组件都是控件.

  8. ios更改UITabBarController背景以及选中背景图片的方法

    一.背景图片  1.5.0以上版本     UIImage *image = [UIImage imageNamed:@"system_tabbar_bg.png"];     [ ...

  9. xss攻击入门

    xss表示Cross Site Scripting(跨站脚本攻击),它与SQL注入攻击类似,SQL注入攻击中以SQL语句作为用户输入,从而达到查询/修改/删除数据的目的,而在xss攻击中,通过插入恶意 ...

  10. PHP漏洞全解(八)-HTTP响应拆分

    本文主要介绍针对PHP网站HTTP响应拆分,站在攻击者的角度,为你演示HTTP响应拆分. HTTP请求的格式 1)请求信息:例如“Get /index.php HTTP/1.1”,请求index.ph ...