spoj 7001
/***
大意:计算gcd(x,y,z) =1 0<= x, y , z <= n 问有多少个这样的对
莫比乌斯反演:(反演: 用结果推原因)
函数m(m)的定义如下:

莫比乌斯反演:
* f(x) = sigma{g(d)}其中x % d == 0,则g(x) = sigma{miu(d) * f(x/d)}
* f(x) = sigma{g(d)}其中d % x == 0,则g(x) = sigma{miu(d/x) * f(d)}
莫比乌斯反演中miu(x) =
* 1 {x中含有偶数个不同的质因子}
* -1 {x中含有奇数个不同的质因子}
* 0 {其他情况}
本题: 设f(x) = 约数为x 的所有数集合 g(x) = 最大公约数gcd 为x的集合
那么g(x) = siga(mu(d)*f(x/d)) x%d==0
或者 g(x) = siga(mu(d/x) *f(d)) d%x==0
在本题中只包含了x,y,z>1 情况 ,,还应加上退化到3个平面上的情况。。
1、 f(x) = n/x*n/x*n/x;----〉 g(x) = mu[i] *(n/x*n/x*n/x)
2、 加上退化到三个平面 ----〉 g(x) = mu[i]*(n/x+1)*(n/x+1)*(n/x+1)
或者分开求:
1、 三个坐标轴。。3
2、 空间中 n/x* n/x*n/x;
3、 三个坐标平面: n/x*n/x +n/x*n/x +n/x*n/x
**/
1、 第一种方法
#include <iostream>
#include <cstring>
using namespace std;
const int maxn = ;
int pri[maxn];
int prime[maxn];
int mu[maxn];
void pri_mu(){
memset(prime,,sizeof(prime));
int cnt =;
mu[] =;
for(int i=;i<maxn;i++){
if(!prime[i]){
mu[i] =-;
pri[cnt++] = i;
}
for(int j=;j<cnt;j++){
if(i*pri[j]>maxn)
break;
prime[i*pri[j]] = ;
if(i%pri[j]==){
mu[i*pri[j]] =;
break;
}else
mu[i*pri[j]] = -mu[i];
}
}
}
int main()
{
pri_mu();
int t;
cin>>t;
long long n;
while(t--){
cin>>n;
long long ans =;
for(int i=;i<=n;i++)
ans += (long long )mu[i]*((n/i+)*(n/i+)*(n/i+)-);
cout<<ans<<endl;
}
return ;
}
----------------------------------------------------------------------------------------------------------
2、 第二种方法
#include <iostream>
#include <cstring>
using namespace std;
const int maxn = ;
int pri[maxn];
int prime[maxn];
int mu[maxn];
void pri_mu(){
memset(prime,,sizeof(prime));
int cnt =;
mu[] =;
for(int i=;i<maxn;i++){
if(!prime[i]){
mu[i] =-;
pri[cnt++] = i;
}
for(int j=;j<cnt;j++){
if(i*pri[j]>maxn)
break;
prime[i*pri[j]] = ;
if(i%pri[j]==){
mu[i*pri[j]] =;
break;
}else
mu[i*pri[j]] = -mu[i];
}
}
}
int main()
{
pri_mu();
int t;
cin>>t;
long long n;
while(t--){
cin>>n;
long long ans =;
for(int i=;i<=n;i++)
ans += (long long )mu[i]*((n/i)*(n/i)*(n/i+));
cout<<ans<<endl;
}
return ;
}
spoj 7001的更多相关文章
- SPOJ 7001 VLATTICE【莫比乌斯反演】
题目链接: http://www.spoj.com/problems/VLATTICE/ 题意: 1≤x,y,z≤n,问有多少对(x,y,z)使得gcd(x,y,z)=1 分析: 欧拉搞不了了,我们用 ...
- 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 - 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 7001 Visible Lattice Points 莫比乌斯,分块
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193 Visible Lattice Points Time L ...
- 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 Visible Lattice Points (莫比乌斯反演)
题意:求一个正方体里面,有多少个顶点可以在(0,0,0)位置直接看到,而不被其它点阻挡.也就是说有多少个(x,y,z)组合,满足gcd(x,y,z)==1或有一个0,另外的两个未知数gcd为1 定义f ...
- spoj 7001 Visible Lattice Points莫比乌斯反演
Visible Lattice Points Time Limit:7000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Su ...
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
随机推荐
- iPhone 5s网络钓鱼邮件,和苹果发布会同步亮相
正如预期的一样,网络犯罪分子会利用Apple最新发表的iPhone 5s消息,几乎在苹果的新产品发表会同时,这个网络钓鱼(Phishing)信件开始流传.此次,趋势科技病毒防治中心 Trend Lab ...
- 关于oracle spfile配置文件问题
$ORACLE_SID决定spfile dbs 默认 在启动Oracle数据库时报错,如下: [oracle@localhost ~]$ sqlplus / as sysdba SQL*Plus: R ...
- document.domain - JavaScript的同源策略问题:错误信息:Permission denied to access property 'document'_eecc00_百度空间
document.domain - JavaScript的同源策略问题:错误信息:Permission denied to access property 'document'_eecc00_百度空间 ...
- UVA - 297Quadtrees(四分图)
Quadtrees Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Statu ...
- 3. 表单输入框 在 IE 中 会有 “X” 和 类似wifi图标的图标出现
原因: IE 自动给 input加了伪类 ::ms-clear 和 ::ms-reveal 解决: input::ms-clear, input::ms-reveal { display: none; ...
- Contributing to Open Source on GitHub(转)
A great way to get involved in open source is to contribute to the existing projects you’re using. G ...
- app 转caf 音频 代码
afconvert /Users/xiaoye/Downloads/cat.caf /Users/xiaoye/Downloads/cat1.caf -d ima4 -f caff -v;
- linux下挂载第二块硬盘
1.第一步:添加硬盘/新建分区(fdisk) a.查看当前系统所有硬盘及分区情况:fdisk -lb.在指定的硬盘(例:/dev/sda)上创建分区:fdisk /dev/sda , 根据提示进行下一 ...
- discuz默认模板文件结构详解-模板文件夹介绍
| — template — default 系统内置风格模板(默认风格)| — template — default – discuz_style_default.xml 风格安装文件,可用 ...
- 在windows下配置对github的操作--基本操作
一.下载安装 git for widows软件 git for widows 是专门用来在windows下操作 github的软件,提供bash(命令行) 和 gui两种方式. 在bash下,其实就是 ...