SPOJ 7001(莫比乌斯反演)
题意: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种).
- #pragma comment(linker,"/STACK:1024000000,1024000000")
- #include <cstdio>
- #include <cstring>
- #include <string>
- #include <cmath>
- #include <limits.h>
- #include <iostream>
- #include <algorithm>
- #include <queue>
- #include <cstdlib>
- #include <stack>
- #include <vector>
- #include <set>
- #include <map>
- #define LL long long
- #define mod 100000000
- #define inf 0x3f3f3f3f
- #define eps 1e-6
- #define N 1000000
- #define lson l,m,rt<<1
- #define rson m+1,r,rt<<1|1
- #define PII pair<int,int>
- using namespace std;
- inline int read()
- {
- char ch=getchar();int x=,f=;
- while(ch>''||ch<''){if(ch=='-')f=-;ch=getchar();}
- while(ch<=''&&ch>=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- bool vis[N+];
- int mu[N+],prime[N+],sum[N+],num[N+];
- void Mobius()
- {
- memset(vis,false,sizeof(vis));
- mu[]=;
- int tot=;
- for(int i=;i<=N;i++)
- {
- if(!vis[i])
- {
- prime[tot++]=i;
- mu[i]=-;
- }
- for(int j=;j<tot;j++)
- {
- if(i*prime[j]>N)break;
- vis[i*prime[j]]=true;
- if(i%prime[j]==)
- {
- mu[i*prime[j]]=;
- break;
- }
- else
- {
- mu[i*prime[j]]=-mu[i];
- }
- }
- }
- for(int i=;i<=N;i++)sum[i]=sum[i-]+mu[i];
- }
- LL solve(int n)
- {
- LL res=;
- for(int i=,last=;i<=n;i=last+)
- {
- last=n/(n/i);
- res+=(LL)(sum[last]-sum[i-])*(n/i)*(n/i)*(n/i+);
- }
- return res;
- }
- int main()
- {
- int T,n;
- Mobius();
- T=read();
- while(T--)
- {
- n=read();
- LL ans=solve(n);
- printf("%lld\n",ans);
- }
- }
SPOJ 7001(莫比乌斯反演)的更多相关文章
- 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 - 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 7001. Visible Lattice Points GCD问题 莫比乌斯反演
SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...
- SPOJ 7001 VLATTICE【莫比乌斯反演】
题目链接: http://www.spoj.com/problems/VLATTICE/ 题意: 1≤x,y,z≤n,问有多少对(x,y,z)使得gcd(x,y,z)=1 分析: 欧拉搞不了了,我们用 ...
- 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 7001. 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 莫比乌斯反演 难度: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 ...
- 【BZOJ2226】[Spoj 5971] LCMSum 莫比乌斯反演(欧拉函数?)
[BZOJ2226][Spoj 5971] LCMSum Description Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n ...
随机推荐
- xcode-build/version-bump
# xcode-build-bump.sh # @desc Auto-increment the build number every time the project is run. # @usag ...
- WPF/Silverlight深度解决方案:(一)解锁被Storyboard束缚的关联属性
原文 WPF/Silverlight深度解决方案:(一)解锁被Storyboard束缚的关联属性 如果您在使用WPF/Silverlight进行相关动画开发中使用了Storyboard,并对关联属性进 ...
- MongoDB shell操作
shell命令操作语法和JavaScript很类似,其实控制台底层的查询语句都是用JavaScript脚本完成操作的.使用shell 命令,需要启动mongo.exe. 常用shell命令如下: 1. ...
- [置顶] 关于本博客 http://www.imobilebbs.com
由于时间上的关系,本博客不再和引路蜂移动软件博客同步更新, 请直接访问 http://www.imobilebbs.com 谢谢您的支持,再见 引路蜂博客
- 第三天学习内容 if--else
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- 学习javascript语言精粹的笔记
1.枚举: 用for in 语句来遍历一个对象中所有的属性名,该枚举过程将会列出所有的属性也包括涵数和方法,如果我们想过滤掉那些不想要的值,最为常用的过滤器为hasOwnProperty方法,以及使用 ...
- 使用jdk的socket通信
使用JDK提供的API进行网络通信,会用到Socket,ServerSocket两个类.写个简单的SERVER和CLIENT之间发消息的小程序,竟然发现了挺多的问题. 这是服务器端代码: packag ...
- 让XP系统支持GPT硬盘
转自 http://article.pchome.net/content-1324506-all.html 1XP系统还不过时 教你完美征服3TB硬盘回顶部 原作者:沈洁 随着高清1080p片源的普及 ...
- php session 管理
function do_login(){ //获取用户名和密码信息,和数据库中比对 echo 111111111; dump($_POST); dump($_SESSION); echo 222222 ...
- OCA读书笔记(3) - 使用DBCA创建Oracle数据库
Objectives: •Create a database by using the Database Configuration Assistant (DBCA) •Generate databa ...