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> ...
随机推荐
- 轻量实用的PHP分页组件:Paginator
来源:https://www.helloweba.com/view-blog-453.html demo:https://www.helloweba.com/demo/2017/Paginator/
- 百度编辑器插入视频、iframe 失败
插入失败是因为编辑器的xssFilter过滤,导致插入出现异常 文件位置:ueditor.config.js ,大概在428行加上 video: ['autoplay', 'controls', 'l ...
- 升级到yosemite后homebrew报错的解决
报错会如下: /usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Ve ...
- 【Postgresql】use
http://www.jianshu.com/p/0ed65e630fd0 http://www.linuxidc.com/Linux/2013-12/94354.htm tag 是一个Array字段 ...
- level 6 - unit 2 - 情态动词May
情态动词May 正式的请求/许可 意思为可以 例如我们在机场候机室听广播的时候,在播报航班前经常听到: may i have your attention ,please ! (请注意听) 在机场过安 ...
- Specified key was too long; max key length is 1000 bytes问题解决
今天使用帆软的报表平台管理,进行外接数据库配置,尝试多次一直提示数据导入失败 java的报错 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorExcep ...
- ios Develop mark
App Distribution Guidehttps://developer.apple.com/library/ios/documaentation/IDEs/Conceptual/AppDist ...
- NAS 创建大文件
不是很懂,但是管用.先记录下来. http://www.111cn.net/sys/linux/55537.htm
- WebGL 进入三维世界
1.观察目标点和上方向 为了确定观察者的状态,你需要获取两项信息:视点,即观察者的位置:观察目标点(look-at point),即被观察目标所在的点,它可以用来确定视线.此外,因为我们需要把观察到的 ...
- python monkey 猴子补丁技术编程,修改python json dumps方法。
1.猴子补丁就是不改变原有模块的内容的前提下,给原有模块新增方法或者修改原有模块. 一个模块的函数,如果希望改变函数的功能,不改变函数名,通常是库模块,你不可能去修改三方库的源码的,实施起来不方便,而 ...