http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4119

依然是三维空间内求(1,1,1)~(a,b,c)能看到的整点数,平移一下转化成(0,0,0)~(a-1,b-1,c-1)就和前一题就一样了

还是莫比乌斯反演求gcd(a,b,c)=1的组数,公式还是sigma{u(d) * ((a/d+1) * (b/d+1) * (c/d+1) - 1)}

但直接暴力会T...所以加了分块优化...因为当a/d,b/d,c/d的值保持不变的时候...可以跳过很多数据

所以维护一下miu的前缀和...中间相同的部分就可以直接得出了

/********************* Template ************************/
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define EPS 1e-8
#define DINF 1e15
#define MAXN 1000050
#define MOD 1000000007
#define INF 0x7fffffff
#define LINF 1LL<<60
#define PI 3.14159265358979323846
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define BUG cout<<" BUG! "<<endl;
#define LINE cout<<" ------------------ "<<endl;
#define FIN freopen("in.txt","r",stdin);
#define FOUT freopen("out.txt","w",stdout);
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,a,b) for(int i = a ; i < b ; i++)
#define read(a) scanf("%d",&a)
#define read2(a,b) scanf("%d%d",&a,&b)
#define read3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define write(a) printf("%d\n",a)
#define write2(a,b) printf("%d %d\n",a,b)
#define write3(a,b,c) printf("%d %d %d\n",a,b,c)
#pragma comment (linker,"/STACK:102400000,102400000")
template<class T> inline T L(T a) {return (a << );}
template<class T> inline T R(T a) {return (a << | );}
template<class T> inline T lowbit(T a) {return (a & -a);}
template<class T> inline T Mid(T a,T b) {return ((a + b) >> );}
template<class T> inline T gcd(T a,T b) {return b ? gcd(b,a%b) : a;}
template<class T> inline T lcm(T a,T b) {return a / gcd(a,b) * b;}
template<class T> inline T Min(T a,T b) {return a < b ? a : b;}
template<class T> inline T Max(T a,T b) {return a > b ? a : b;}
template<class T> inline T Min(T a,T b,T c) {return min(min(a,b),c);}
template<class T> inline T Max(T a,T b,T c) {return max(max(a,b),c);}
template<class T> inline T Min(T a,T b,T c,T d) {return min(min(a,b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d) {return max(max(a,b),max(c,d));}
template<class T> inline T exGCD(T a, T b, T &x, T &y){
if(!b) return x = ,y = ,a;
T res = exGCD(b,a%b,x,y),tmp = x;
x = y,y = tmp - (a / b) * y;
return res;
}
template<class T> inline T reverse_bits(T x){
x = (x >> & 0x55555555) | ((x << ) & 0xaaaaaaaa); x = ((x >> ) & 0x33333333) | ((x << ) & 0xcccccccc);
x = (x >> & 0x0f0f0f0f) | ((x << ) & 0xf0f0f0f0); x = ((x >> ) & 0x00ff00ff) | ((x << ) & 0xff00ff00);
x = (x >> & 0x0000ffff) | ((x <<) & 0xffff0000); return x;
}
typedef long long LL; typedef unsigned long long ULL;
//typedef __int64 LL; typedef unsigned __int64 ULL; /********************* By F *********************/
int T,cnt;
int prime[MAXN];
int pri[MAXN];
int miu[MAXN];
int sum[MAXN];
/* 莫比乌斯筛 */
void pre_miu(){
miu[] = ;
for(int i = ; i < MAXN ; i++){
if(!prime[i]){
miu[i] = -;
pri[cnt++] = i;
}
for(int j = ; j < cnt && i * pri[j] <= MAXN ; j++){
prime[i * pri[j]] = ;
if(i % pri[j] == ){
miu[i * pri[j]] = ;
break;
}else miu[i * pri[j]] = -miu[i];
}
}
for(int i = ; i < MAXN ; i++) sum[i] = sum[i-] + miu[i];
}
int main(){
//FIN;
//FOUT;
pre_miu();
int a,b,c;
while(~scanf("%d%d%d",&a,&b,&c)){
a--;b--;c--;
int m = Max(a,b,c);
LL res = ;
for(int i = ,now = INF ; i <= m ; i = now+){
now = Min(a/i ? a/(a/i) : INF , b/i ? b/(b/i) : INF , c/i ? c/(c/i) : INF);
res += ((LL)(a/now+) * (LL)(b/now+) * (LL)(c/now+) - ) * (sum[now] - sum[i-]);
}
printf("%lld\n",res);
}
return ;
}

ZOJ 3435 Ideal Puzzle Bobble 莫比乌斯反演的更多相关文章

  1. ZOJ 3435 Ideal Puzzle Bobble

    ZOJ Problem Set - 3435 Ideal Puzzle Bobble Time Limit: 2 Seconds      Memory Limit: 65536 KB Have yo ...

  2. [ZOJ3435]Ideal Puzzle Bobble

    题面戳我 题意:你现在处于\((1,1,1)\),问可以看见多少个第一卦限的整点. 第一卦限:就是\((x,y,z)\)中\(x,y,z\)均为正 sol 首先L--,W--,H--,然后答案就变成了 ...

  3. zoj3435(莫比乌斯反演)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3435 题意: 给出一个三维坐标 (x, y, z), 问该点与 ...

  4. hdu1695 GCD(莫比乌斯反演)

    题意:求(1,b)区间和(1,d)区间里面gcd(x, y) = k的数的对数(1<=x<=b , 1<= y <= d). 知识点: 莫比乌斯反演/*12*/ 线性筛求莫比乌 ...

  5. BZOJ 2154: Crash的数字表格 [莫比乌斯反演]

    2154: Crash的数字表格 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 2924  Solved: 1091[Submit][Status][ ...

  6. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  7. Bzoj2154 Crash的数字表格 乘法逆元+莫比乌斯反演(TLE)

    题意:求sigma{lcm(i,j)},1<=i<=n,1<=j<=m 不妨令n<=m 首先把lcm(i,j)转成i*j/gcd(i,j) 正解不会...总之最后化出来的 ...

  8. 莫比乌斯函数筛法 & 莫比乌斯反演

    模板: int p[MAXN],pcnt=0,mu[MAXN]; bool notp[MAXN]; void shai(int n){ mu[1]=1; for(int i=2;i<=n;++i ...

  9. 【BZOJ-2440】完全平方数 容斥原理 + 线性筛莫比乌斯反演函数 + 二分判定

    2440: [中山市选2011]完全平方数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2371  Solved: 1143[Submit][Sta ...

随机推荐

  1. 时间就是金钱HNCOI2000(最短路)

    时间就是金钱HNCOI2000 版权声明:本篇随笔版权归作者YJSheep(www.cnblogs.com/yangyaojia)所有,转载请保留原地址! 人们总是选时间最短或费用最低的路线 例如, ...

  2. solr在windows下的安装及配置

    solr在windows下的安装及配置 首先,solr是基于Java开发的,所以使用的话需要先进行java环境的配置,在Java环境配置好之后就可以去http://www.apache.org/dyn ...

  3. ASP.NET-跨站伪造请求CSRF

    经常看到在项目中ajax post数据到服务器不加防伪标记,造成CSRF攻击,在Asp.net Mvc里加入防伪标记很简单在表单中加入Html.AntiForgeryToken()即可Html.Ant ...

  4. 50个经典Sql语句

    50个经典Sql语句 --1.学生表 Student(S,Sname,Sage,Ssex) --S 学生编号,Sname 学生姓名,Sage 出生年月,Ssex 学生性别 --2.课程表  Cours ...

  5. Swift编写的一些完整的app

    收集了一些实用swift编写的app,这些demo都是不错的值得学习的. 知乎日报 Swift-ZhihuDaily Swift版知乎日报 参照了YANGReal的糗事百科和uitableview的例 ...

  6. STM32中assert_param的使用

    在STM32的固件库和提供的例程中.到处都能够见到assert_param()的使用. 假设打开不论什么一个例程中的stm32f10x_conf.h文件,就能够看到实际上assert_param是一个 ...

  7. BootStrap有用代码片段(持续总结)

    > 如题.持续总结自己在使用BootStrap中遇到的问题.并记录解决方法.希望能帮到须要的小伙伴 1.bootstrap上下布局.顶部固定下部填充 应用场景:经典上下布局中,顶部导航条固定,下 ...

  8. django 笔记15 ajax系列

    参考 http://www.cnblogs.com/wupeiqi/articles/5703697.html # 原生操作# jQuery操作# 伪Ajax操作# XMLHttpReques 伪aj ...

  9. java9新特性-8-语法改进:钻石操作符(Diamond Operator)使用升级

    1.使用说明 我们将能够与匿名实现类共同使用钻石操作符(diamond operator) 在java8中如下的操作是会报错的:   编译报错信息:'<>' cannot be used ...

  10. RelativeLayout中的baseline

    比如,加入两个相邻的TextView,给第二个TextView一个大一点的padding(比如20dp),如果加了layout_alignBaseline到第二个TextView中的话, TextVi ...