传送门:Visible Lattice Points

题意:0<=x,y,z<=n,求有多少对xyz满足gcd(x,y,z)=1。

设f(d) = GCD(a,b,c) = d的种类数 ;

F(n) 为GCD(a,b,c) = d 的倍数的种类数, n%a == 0 n%b==0 n%c==0。

即 :F(d) = (N/d)*(N/d)*(N/d);

则f(d) = sigma( mu[n/d]*F(n), d|n )

由于d = 1 所以f(1) = sigma( mu[n]*F(n) ) = sigma( mu[n]*(N/n)*(N/n)*(N/n) );

由于0能够取到,所以对于a,b,c 要讨论一个为0 ,两个为0的情况 (3种).

  1. #pragma comment(linker,"/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <string>
  5. #include <cmath>
  6. #include <limits.h>
  7. #include <iostream>
  8. #include <algorithm>
  9. #include <queue>
  10. #include <cstdlib>
  11. #include <stack>
  12. #include <vector>
  13. #include <set>
  14. #include <map>
  15. #define LL long long
  16. #define mod 100000000
  17. #define inf 0x3f3f3f3f
  18. #define eps 1e-6
  19. #define N 1000000
  20. #define lson l,m,rt<<1
  21. #define rson m+1,r,rt<<1|1
  22. #define PII pair<int,int>
  23. using namespace std;
  24. inline int read()
  25. {
  26. char ch=getchar();int x=,f=;
  27. while(ch>''||ch<''){if(ch=='-')f=-;ch=getchar();}
  28. while(ch<=''&&ch>=''){x=x*+ch-'';ch=getchar();}
  29. return x*f;
  30. }
  31. bool vis[N+];
  32. int mu[N+],prime[N+],sum[N+],num[N+];
  33. void Mobius()
  34. {
  35. memset(vis,false,sizeof(vis));
  36. mu[]=;
  37. int tot=;
  38. for(int i=;i<=N;i++)
  39. {
  40. if(!vis[i])
  41. {
  42. prime[tot++]=i;
  43. mu[i]=-;
  44. }
  45. for(int j=;j<tot;j++)
  46. {
  47. if(i*prime[j]>N)break;
  48. vis[i*prime[j]]=true;
  49. if(i%prime[j]==)
  50. {
  51. mu[i*prime[j]]=;
  52. break;
  53. }
  54. else
  55. {
  56. mu[i*prime[j]]=-mu[i];
  57. }
  58. }
  59. }
  60. for(int i=;i<=N;i++)sum[i]=sum[i-]+mu[i];
  61. }
  62. LL solve(int n)
  63. {
  64. LL res=;
  65. for(int i=,last=;i<=n;i=last+)
  66. {
  67. last=n/(n/i);
  68. res+=(LL)(sum[last]-sum[i-])*(n/i)*(n/i)*(n/i+);
  69. }
  70. return res;
  71. }
  72.  
  73. int main()
  74. {
  75. int T,n;
  76. Mobius();
  77. T=read();
  78. while(T--)
  79. {
  80. n=read();
  81. LL ans=solve(n);
  82. printf("%lld\n",ans);
  83. }
  84. }

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

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

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

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

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

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

  4. spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演

    SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...

  5. SPOJ 7001 VLATTICE【莫比乌斯反演】

    题目链接: http://www.spoj.com/problems/VLATTICE/ 题意: 1≤x,y,z≤n,问有多少对(x,y,z)使得gcd(x,y,z)=1 分析: 欧拉搞不了了,我们用 ...

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

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

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

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

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

  9. 【BZOJ2226】[Spoj 5971] LCMSum 莫比乌斯反演(欧拉函数?)

    [BZOJ2226][Spoj 5971] LCMSum Description Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n ...

随机推荐

  1. xcode-build/version-bump

    # xcode-build-bump.sh # @desc Auto-increment the build number every time the project is run. # @usag ...

  2. WPF/Silverlight深度解决方案:(一)解锁被Storyboard束缚的关联属性

    原文 WPF/Silverlight深度解决方案:(一)解锁被Storyboard束缚的关联属性 如果您在使用WPF/Silverlight进行相关动画开发中使用了Storyboard,并对关联属性进 ...

  3. MongoDB shell操作

    shell命令操作语法和JavaScript很类似,其实控制台底层的查询语句都是用JavaScript脚本完成操作的.使用shell 命令,需要启动mongo.exe. 常用shell命令如下: 1. ...

  4. [置顶] 关于本博客 http://www.imobilebbs.com

    由于时间上的关系,本博客不再和引路蜂移动软件博客同步更新,    请直接访问 http://www.imobilebbs.com 谢谢您的支持,再见   引路蜂博客

  5. 第三天学习内容 if--else

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  6. 学习javascript语言精粹的笔记

    1.枚举: 用for in 语句来遍历一个对象中所有的属性名,该枚举过程将会列出所有的属性也包括涵数和方法,如果我们想过滤掉那些不想要的值,最为常用的过滤器为hasOwnProperty方法,以及使用 ...

  7. 使用jdk的socket通信

    使用JDK提供的API进行网络通信,会用到Socket,ServerSocket两个类.写个简单的SERVER和CLIENT之间发消息的小程序,竟然发现了挺多的问题. 这是服务器端代码: packag ...

  8. 让XP系统支持GPT硬盘

    转自 http://article.pchome.net/content-1324506-all.html 1XP系统还不过时 教你完美征服3TB硬盘回顶部 原作者:沈洁 随着高清1080p片源的普及 ...

  9. php session 管理

    function do_login(){ //获取用户名和密码信息,和数据库中比对 echo 111111111; dump($_POST); dump($_SESSION); echo 222222 ...

  10. OCA读书笔记(3) - 使用DBCA创建Oracle数据库

    Objectives: •Create a database by using the Database Configuration Assistant (DBCA) •Generate databa ...