SPOJ 7001 VLATTICE【莫比乌斯反演】
题目链接:
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(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【莫比乌斯反演】的更多相关文章
- SPOJ 7001 VLATTICE - Visible Lattice Points(莫比乌斯反演)
		题目链接:http://www.spoj.com/problems/VLATTICE/ 题意:求gcd(a, b, c) = 1 a,b,c <=N 的对数. 思路:我们令函数g(x)为g ... 
- 【BZOJ2226】[Spoj 5971] LCMSum 莫比乌斯反演(欧拉函数?)
		[BZOJ2226][Spoj 5971] LCMSum Description Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n ... 
- 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 ... 
- BZOJ 2226: [Spoj 5971] LCMSum  莫比乌斯反演 + 严重卡常
		Code: #pragma GCC optimize(2) #include<bits/stdc++.h> #define setIO(s) freopen(s".in" ... 
- spoj  7001. Visible Lattice Points GCD问题 莫比乌斯反演
		SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ... 
- 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 ... 
- 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 (莫比乌斯反演基础题)
		Visible Lattice Points Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at ... 
- [SPOJ VLATTICE]Visible Lattice Points 数论 莫比乌斯反演
		7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0, ... 
随机推荐
- 如何用 CSS 和 D3 创作火焰动画
			效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/xJdVxx 可交互视频 ... 
- PHP安装Xcache扩展
			简述 XCache 是一个又快又稳定的 PHP opcode 缓存器. 经过良好的测试并在大流量/高负载的生产机器上稳定运行. 经过(在 linux 上)测试并支持所有现行 PHP 分支的最新发布 ... 
- thinkphp5开发restful-api接口 学习笔记一
			视频学习地址: http://study.163.com/course/courseMain.htm?courseId=1004171002 源码和文档(如果满意,欢迎 star): https:// ... 
- POJ:1904-King's Quest
			King's Quest Time limit15000 ms Case time limit2000 ms Memory limit65536 kB Description Once upon a ... 
- ACM Changchun 2015    L . House Building
			Have you ever played the video game Minecraft? This game has been one of the world's most popular ga ... 
- Http协议——基本概念
			一.浏览网页的过程 用户输入一个url,浏览器根据url给web服务器发送一个Request,web服务器接收到Request后进行处理,并返回浏览器一个Response,可以响应一个静态页面或者图片 ... 
- PHP中文网 学习阶段规划
			1.第一阶段: 前端基础 前端基础课程大纲 教学内容 教学重点 1.HTML5 HTML简介.HTML标签详解.字符编码的奥秘.Html5新特性与常用标签 2.CSS3 CSS简介.CSS的引入方式. ... 
- jquery获得iframe内容的高度
			html: <iframe name="rightgp" id="right_frame_h" src="/Poster/rightgp&quo ... 
- 学习C++的第四天
			1.头文件中的 #ifndef/#define/#endif 防止该头文件被重复引用” //文件路径名:el_1\hello.h #ifndef _HELLO /////如果没有定义 _HELLO文件 ... 
- Graham扫描法 --求凸包
			前言: 首先,什么是凸包? 假设平面上有p0~p12共13个点,过某些点作一个多边形,使这个多边形能把所有点都“包”起来.当这个多边形是凸多边形的时候,我们就叫它“凸包”.如下图: 然后,什么是凸包 ... 
