题目链接: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. 如何在IE8下调试OCX控件

    第一种方式 多进程模式下, 在IE8打开web页面, 然后在调试菜单选择附加到进程, 这时看到2个IE进程, 选择没有带标题的, 也就是主进程, 就可以正常调试了. 此方式比较麻烦, 不能F5直接启动 ...

  2. [LeetCode][Python]Longest Substring Without Repeating Characters

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...

  3. MyEclipse修改

    MyEclipse设置编码方式 http://www.cnblogs.com/susuyu/archive/2012/06/27/2566062.html Eclipse添加Spket插件实现ExtJ ...

  4. android 回调

    调函数(callback Function),顾名思义,用于回调的函数.  回调函数只是一个功能片段,由用户按照回调函数调用约定来实现的一个函数.回调函数是一个工作流的一部分,由工作流来决定函数的调用 ...

  5. HDU 4715 Difference Between Primes (打表)

    Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...

  6. 2048小游戏(C语言版)

    #include <climits> #include <cstdio> #include <cstring> #include <stack> #in ...

  7. 升级python的sqlite库版本

    今天了解了一下用python获取chrome cookie信息,在研究的过程中,发现打开数据库失败,后来调查了一下发现是由于sqlite3库太老的缘故,起码需要3.8以上,然后看了一下python 2 ...

  8. java新特性之可变参数

    public class NewDemo01 {     public static void main(String[] args) {         System.out.print(" ...

  9. IOS 特定于设备的开发:使用加速能力“向上定位”

    iPhone提供了3个机载的传感器,用于沿着iPhone的3根相互垂直的轴(左/右(x轴).上/下(y轴)和前/后(z轴))度量加速能力.这些值指示作用于iPhone的力,它们来自重力和用户移动.可以 ...

  10. Ubuntu12.04获取root权限

    有的时候我们需要Ubuntu的root权限,我们该如何获取呢? 其实,很简单,我们只需要在终端中输入以下命令即可获得root权限. 第一步,打开终端 ( ctrl+alt+T ) 第二步,输入命令:s ...