ZOJ 3435 Ideal Puzzle Bobble
Time Limit: 2 Seconds Memory Limit: 65536 KB
Have you ever played Puzzle Bobble, a very famous PC game? In this game, as a very cute bobble dragon, you must keep shooting powerful bubbles to crush all the colorful bubbles upwards. Victory comes when all the bubbles upwards are crushed.
Little Tom is crazy about this game. One day, he finds that all kinds of Puzzle Bobble are 2D Games. To be more excited when playing this game, he comes up with a new idea to design a 3D Puzzle Bobble game! In this game, the bobble dragon is standing in a cubic room with L in length, W in width and H in height. Around him are so many colorful bubbles. We can use 3D Cartesian coordinates (x, y, z) to represent the locations of the bobble dragon and those bubbles. All these coordinates (x, y, z) are triple positive integers ranged from (1, 1, 1) to (L, W, H).
To simplify the problem, let's assume the bobble dragon is standing at (1, 1, 1) in the room. And there is one colorful bubble at every (x, y, z) in the room except (1, 1, 1). The dragon is so strong that he can shoot out a magical bubble to crush all the colorful bubbles in the straight line which the magical bubble flies every single time. Note that bubbles are significantly small with respect to the distances between each two bubbles. Our question remains, how many magical bubbles will the cute dragon shoot before crushing all the colorful bubbles around him?

Input
There are multiple cases, no more than 200. Each case contains one single line. In this line, there are three positive integers L, W and H (2 ≤ L, W, H ≤ 1000000) which describes the size of the room. Proceed to the end of the file.
Output
For each case, print the number of the magical bubbles needed to crush all the colorful bubbles in one line.
Sample Input
2 2 2
3 3 3
Sample Output
7
19
Author: ZHU, Yuke
Contest: ZOJ Monthly, November 2010
求(1,1,1)至(x,y,z)的互质个数。
即求(0,0,0)到(x-1,y-1,z-1)互质个数。
剩下的同SPOJ1007 VLATTICE - Visible Lattice Points
#include<cstdio>
#include<iostream>
#ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif
using namespace std;
typedef long long ll;
const int M=1e6+;
int L,W,H,T;ll sum[M];
int tot,prime[M/],mu[M];bool check[M];
void sieve(){
int n=1e6;mu[]=;
for(int i=;i<=n;i++){
if(!check[i]) prime[++tot]=i,mu[i]=-;
for(int j=;j<=tot&&i*prime[j]<=n;j++){
check[i*prime[j]]=;
if(!(i%prime[j])){mu[i*prime[j]]=;break;}
else mu[i*prime[j]]=-mu[i];
}
}
for(int i=;i<=n;i++) sum[i]=sum[i-]+mu[i];
}
inline ll solve(int x,int y,int z){
int t=min(x,min(y,z));
ll ans=;
for(int i=,pos;i<=t;i=pos+){
pos=min(x/(x/i),min(y/(y/i),z/(z/i)));
ans+=1LL*(x/i)*(y/i)*(z/i)*(sum[pos]-sum[i-]);
}
t=min(x,y);
for(int i=,pos;i<=t;i=pos+){
pos=min(x/(x/i),y/(y/i));
ans+=1LL*(x/i)*(y/i)*(sum[pos]-sum[i-]);
}
t=min(y,z);
for(int i=,pos;i<=t;i=pos+){
pos=min(y/(y/i),z/(z/i));
ans+=1LL*(y/i)*(z/i)*(sum[pos]-sum[i-]);
}
t=min(x,z);
for(int i=,pos;i<=t;i=pos+){
pos=min(x/(x/i),z/(z/i));
ans+=1LL*(x/i)*(z/i)*(sum[pos]-sum[i-]);
}
return ans;
}
int main(){
sieve();
while(~scanf("%d%d%d",&L,&W,&H)){
L--,W--,H--;
printf(LL"\n",solve(L,W,H));
}
return ;
}
ZOJ 3435 Ideal Puzzle Bobble的更多相关文章
- ZOJ 3435 Ideal Puzzle Bobble 莫比乌斯反演
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4119 依然是三维空间内求(1,1,1)~(a,b,c)能看到的整点数,平移一下 ...
- [ZOJ3435]Ideal Puzzle Bobble
题面戳我 题意:你现在处于\((1,1,1)\),问可以看见多少个第一卦限的整点. 第一卦限:就是\((x,y,z)\)中\(x,y,z\)均为正 sol 首先L--,W--,H--,然后答案就变成了 ...
- ZOJ 1602 Multiplication Puzzle(区间DP)题解
题意:n个数字的串,每取出一个数字的代价为该数字和左右的乘积(1.n不能取),问最小代价 思路:dp[i][j]表示把i~j取到只剩 i.j 的最小代价. 代码: #include<set> ...
- [ZOJ]3541 Last Puzzle (区间DP)
ZOJ 3541 题目大意:有n个按钮,第i个按钮在按下ti 时间后回自动弹起,每个开关的位置是di,问什么策略按开关可以使所有的开关同时处于按下状态 Description There is one ...
- [ZOJ 2836] Number Puzzle
Number Puzzle Time Limit: 2 Seconds Memory Limit: 65536 KB Given a list of integers (A1, A2, .. ...
- ZOJ3435_Ideal Puzzle Bobble
把L,H,W分别减一就变成上面一个题目了. 不多说,也不召唤代码君了.
- ZOJ 3814 Sawtooth Puzzle (2014年牡丹江赛区网络赛F题)
1.题目描写叙述:点击打开链接 2.解题思路:本题是一道隐式图的搜索题目.一般来说,这类题目首先要定义状态,接下来是弄清楚状态怎样转移,以及状态怎样判重,怎样推断当前状态是否和目标状态同样.至于求解最 ...
- ZOJ 3435
求(1,1,1)至(x,y,z)的互质个数. 即求(0,0,0)到(x-1,y-1,z-1)互质个数. 依然如上题那样做.但很慢...好像还有一个分块的思想,得学学. #include <ios ...
- ZOJ 2836 Number Puzzle 题解
题面 lcm(x,y)=xy/gcd(x,y) lcm(x1,x2,···,xn)=lcm(lcm(x1,x2,···,xn-1),xn) #include <bits/stdc++.h> ...
随机推荐
- 【伪装位置神器】神行者AnyLocation 1.3.0001可用于微信,陌陌
<ignore_js_op> 软件名称:神行者(破解)软件版本:v1.3.0001授权类别:免费测试机型:大可乐手机 下载链接: http://pan.baidu.com/s/1qWwSM ...
- SSH上传和下载文件
备个份: 一,ssh上传文件 scp file username@hostIP:文件地址 例: [zhangy@BlackGhost ~]$ scp test.sql zhangying@192.16 ...
- 如何获取ABBYY FineReader 12注册码-激活码-序列号
提及OCR文字识别软件,相信不少人会脱口而出ABBYY FineReader,这款软件当前最新版本为FineReader 12,是市场领先的OCR图文识别软件,不仅可以将纸质文档和PDF文件以及图像文 ...
- QT OpenGL绘制三维图形(立方体、圆柱体、圆锥、球体、圆环等等)
本文使用QGLWidget来绘制各种三维基本图形,包括立方体.圆柱体.圆锥.球体.圆环等等,涉及包括基本绘制以及上色.纹理.旋转等操作. 使用的软件版本:QT5.12 + QT Creater4.8. ...
- Bootstrap 各种进度条详解
一:默认的进度条 创建一个基本的进度条的步骤如下: 添加一个带有 class .progress 的 <div>. 接着,在上面的 <div> 内,添加一个带有 class . ...
- kettle教程一
转载:http://www.cnblogs.com/limengqiang/archive/2013/01/16/KettleApply1.html ETL(Extract-Transform-Loa ...
- spring boot整合activemq消息中间件
spring boot整合activemq消息中间件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi ...
- python 上下文处理错误,记录日志
之前发过了装饰器版本的异常记录日志,但是需要装饰在函数或方法上.此篇用上下文管理,用一个with就能记录错误了,不需要写成函数. import traceback # pip install mult ...
- Linux命令缩写的全称
[目录|文件] ls : list(列出目录内容) pwd : print work directory(打印当前目录,现示当前工作目录的绝对路径) cd : change directory(改变目 ...
- C#客户端嵌入Chrome浏览器的实现
https://blog.csdn.net/lanwilliam/article/details/79639823 客户端软件,也就是传统的Winform软件,在很多时候是很好用的.因为在做一些打印. ...