题目链接:

http://www.spoj.com/problems/VLATTICE/

题意:

1≤x,y,z≤n,问有多少对(x,y,z)使得gcd(x,y,z)=1

分析:

欧拉搞不了了,我们用莫比乌斯来搞一搞。

同样,我们设

f(d):满足gcd(x,y,z)=d且x,y,z均在给定范围内的(x,y,z)的对数。

F(d):满足d|gcd(x,y,z)且x,y,z均在给定范围内的(x,y,z)的对数。

显然F(d)=[n/d][n/d][n/d],反演后我们得到

f(x)=∑x|dμ(d/x)[n/d]∗[n/d]∗[n/d]

直接求解f(1)即可。

特别注意坐标轴上的点和坐标平面上的点。

代码:

/*
-- SPOJ 7001
-- mobius
-- Create by jiangyuzhu
-- 2016/5/30
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <stack>
using namespace std;
typedef long long ll;
#define sa(n) scanf("%d", &(n))
#define sal(n) scanf("%I64d", &(n))
#define pl(x) cout << #x << " " << x << endl
#define mdzz cout<<"mdzz"<<endl;
const int maxn = 1e6 + 5 ;
int tot = 0;
int miu[maxn], prime[maxn], f[maxn];
bool flag[maxn];
void mobius()
{
miu[1] = 1;
tot = 0;
for(int i = 2; i < maxn; i++){
if(!flag[i]){
prime[tot++] = i;
miu[i] = -1;
}
for(int j = 0; j < tot && i * prime[j] < maxn; j++){
flag[i * prime[j]] = true;
if(i % prime[j]) miu[i * prime[j]] = -miu[i];
else{
miu[i * prime[j]] = 0;
break;
}
}
}
}
int main (void)
{
mobius();
int T;sa(T);
int n;
for(int kas = 1; kas <= T; kas++){
scanf("%d", &n);
ll ans = 3;
for(int i = 1; i <= n; i++){
ans += miu[i] * 1ll * (n/ i) * (n / i) * (n / i + 3);
}
printf("%lld\n", ans);
}
return 0;
}

SPOJ 7001 VLATTICE【莫比乌斯反演】的更多相关文章

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

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

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

  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. BZOJ 2226: [Spoj 5971] LCMSum 莫比乌斯反演 + 严重卡常

    Code: #pragma GCC optimize(2) #include<bits/stdc++.h> #define setIO(s) freopen(s".in" ...

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

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

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

  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 (莫比乌斯反演基础题)

    Visible Lattice Points Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at ...

  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. 流程控制之while循环for循环

    流程控制之while循环1.什么是循环 循环就是重复做某件事2.为什么要有循环 为了让计算机能够具备人重复做某件事的能力3.如何用循环 while语法: while 条件: code1 code2 c ...

  2. Python基础(五)——闭包与lambda的结合

    (1)变量的域 要了解闭包需要先了解变量的域,也就是变量在哪一段“上下文”是有效的(类似局部变量和全局变量的区别),举一个很简单的例子.(例子不重要,就是涉及闭包就要时刻关注这个域) def test ...

  3. 剑指Offer(书):不用四则运算做加法

    题目:写一个函数,求两个整数之和,不得使用四则运算位运算. package com.gjjun.jzoffer; /** * 写一个函数,求两个整数之和,不得使用四则运算 * * @author gj ...

  4. jmeter jdbc各字段的含义

    JDBC采样器各选项的含义如下: 1.Variable Name 其中的Variable Name和上面JDBC Connection Configuration中的Variable Name相同,这 ...

  5. Elasticsearch安装---安装运行es

    1.进入到elasticsearch cd /data/webroot/www/elasticsearch/elasticsearch-5.6.3 2.运行:sh ./bin/elasticsearc ...

  6. HDU 3486 Interviewe RMQ

    题意: 将\(n\)个数分成\(m\)段相邻区间,每段区间的长度为\(\left \lfloor \frac{n}{m} \right \rfloor\),从每段区间选一个最大值,要让所有的最大值之和 ...

  7. 《Scrum实战》第2次课【取得大家的支持】课后作业汇总

    作业:<变革之心>读后感 孟帅: 2017-7-12http://www.cnblogs.com/mengshuai1982/p/7153985.html

  8. Freemaker模板指令

    ${...}:Freemaker将会输出真实的值来替换大括号内的表达式.这样的表达式被称为interpolation(插值). FTL标签(Freemaker模板的语言标签):FTL标签和HTML标签 ...

  9. luogu1725 琪露诺

    单调队列 #include <iostream> #include <cstdio> using namespace std; int n, l, r, dp[400005], ...

  10. Selenium 报错:Element is not clickable at point

    WebDriverException: unknown error: Element <td class="grid - select - input " stype=&qu ...