题目链接:http://www.spoj.com/problems/VLATTICE/

题意:求gcd(a, b, c) = 1    a,b,c <=N 的对数。

思路:我们令函数g(x)为gcd(a, b, c) = x的对数,那么这题就是要求g(1)。我们令f(x)为x | gcd(a, b, c)的对数,显然f(n) = sigma(n | d, g(d)) 。f(d) = (n/d) * (n/d) * (n/d),那么我们就可以用莫比乌斯反演公式了, g(n) = sigma(n | d, mu(d/n)f(d))   g(1) = mu(d)f(d) = mu(d)*(n/d)*(n/d)*(n/d)。考虑1位为0,2位为0的情况。

莫比乌斯反演的两种形式:

g(n) = sigma(d | n, f(d))   f(n) = sigma(d | n, mu(d) * g(n/d))

g(n) = sigma(n | d, f(d))   f(n) = sigma(n | d, mu(d / n) * g(d))

code:

 #include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
const int MAXN = ;
bool check[MAXN];
int primes[MAXN];
int mu[MAXN]; void moblus()
{
memset(check, false, sizeof(check));
mu[] = ;
int cnt = ;
for (int i = ; i < MAXN; ++i) {
if (!check[i]) {
primes[cnt++] = i;
mu[i] = -;
}
for (int j = ; j < cnt; ++j) {
if (i * primes[j] > MAXN) break;
check[i * primes[j]] = true;
if (i % primes[j] == ) {
mu[i * primes[j]] = ;
break;
} else {
mu[i * primes[j]] = -mu[i];
}
}
}
} int main()
{
moblus();
int nCase;
scanf("%d", &nCase);
while (nCase--) {
int n;
scanf("%d", &n);
LL ans = ; // 001 010 100
for (int i = ; i <= n; ++i) {
ans += (LL)mu[i] * (n / i) * (n / i) * (n / i + );
}
printf("%lld\n", ans);
}
return ;
}

 

SPOJ 7001 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 VLATTICE Visible Lattice Points 莫比乌斯反演

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

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

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

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

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

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

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

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

    题目链接 /* http://www.spoj.com/problems/VLATTICE/ 题意:求一个n*n*n的晶体,有多少点可以在(0,0,0)处可以直接看到. 同BZOJ.2301 题目即要 ...

  8. SPOJ1007 VLATTICE - Visible Lattice Points

    VLATTICE - Visible Lattice Points no tags  Consider a N*N*N lattice. One corner is at (0,0,0) and th ...

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

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

随机推荐

  1. android:configChanges 屏幕横竖屏切换

    出处:http://blog.csdn.net/djy1992/article/details/9378195 --->  android:screenOrientation="por ...

  2. NSFileHandle编写json数据格式

    代码如下: + (void)writeToFile:(NSDictionary *)params filePath:(NSString *)path { NSData *jsonData = [sel ...

  3. android样式布局---&gt;ListView(附上源代码)

    在android应用开发过程中,Listview 是经常使用的数据展现控件,往往用于显示列表形式的数据. 假设只显示数据往往会显得非常单调.非常多时候依据须要定义不同的item 背景选项.比如定义数据 ...

  4. 【Linux学习】Ubuntu下嵌入式交叉编译环境arm-linux-gcc搭建

    (1)首先选择一个路径用来存放arm-linux-gcc.我选用的是/home/book,并在以下建立一个目录arm-linux-gcc. (2)利用cp EABI-4.3.3_Emdedsky_20 ...

  5. VBA 简单调试

    在中断模式下(ctrl+Break键),可以做: 1.执行    工具----选项----编辑器----勾选“自动显示数据提示” 则当用鼠标悬停在变量或表达式上时,会出现提示窗口,显示其名称和值! 2 ...

  6. Svn服务启动的两种方式

    一.svn服务器启动 › cmd命令行启动:vsvnserve -d –r 文档仓库路径 -d 后台执行 › -r 版本库的根目录 二.›Windows服务自动启动     利用xp.2000 以上的 ...

  7. Java 动态代理(转)

    一.代理模式 代理模式是常用的java设计模式,他的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理消息.过滤消息.把消息转发给委托类,以及事后 处理消息等.代理类与委托类之间通常会存在 ...

  8. LineCalc,一个基于Lex&Yacc的简单行计算工具

    LineCalc是基于Lex&Yacc的一个简单的行计算工具,支持常见的运算符和部分POSIX中定义于math.h中的数学函数:同时,LineCalc还提供了一个简单的错误处理模块,能检测公式 ...

  9. Android 快速选择联系人

    Activity 代码如下: /* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache ...

  10. hdu 3397 Sequence operation 线段树

    题目链接 给出n个数, 每个数是0或1, 给5种操作, 区间变为1, 区间变为0, 区间0,1翻转, 询问区间内1的个数, 询问区间内最长连续1的个数. 需要将数组开成二维的, 然后区间0, 1翻转只 ...