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> ...
随机推荐
- Objective-c: 移除字符串中的指定字符
string = [[string componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInS ...
- Python之XML解析详解
什么是XML? XML 指可扩展标记语言(eXtensible Markup Language). XML 被设计用来传输和存储数据. XML是一套定义语义标记的规则,这些标记将文档分成许多部件并对这 ...
- 怎样把网站升级到http/2
https://juejin.im/post/59c63adf6fb9a00a4c271484
- Eclipse------导入项目后出现javax.servlet.jsp cannot be resolved to a type
报错信息:javax.servlet.jsp cannot be resolved to a type 原因1: 这个错误可能是服务器自带的servlet库未导入的原因. 解决方法: 右键项目&quo ...
- Oracle分析関数
Oracleの分析関数のサンプル集 概要 Oracleコミュニティでよく見かける分析関数の使用例を 習うより慣れろ形式で.分析関数のイメージを付けて.まとめて紹介します. Oracle11gR1で動作 ...
- 8 -- 深入使用Spring -- 1...4 属性占位符配置器
8.1.4 属性占位符配置器 PropertyPlaceholderConfigurer 是一个容器后处理器,负责读取Properties属性文件里的属性值,并将这些属性值设置成Spring配置文件的 ...
- grid网格的流动grid-auto-flow属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ios开发之--tableview刷新某一个区和某一行
在开发中,有时候,我们不需要刷新整个表,只需要刷新局部数据即可,具体代码如下: //section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWith ...
- ios开发之--所有设备的屏幕尺寸
所有设备型号官网地址:https://www.theiphonewiki.com/wiki/Models iPhone: 机型 像素 比例 像素密度 屏幕尺寸 机型代码 发布日期 iPhone 2g ...
- IE8兼容性调试及IE 8 css hack
做网站开发,一提到IE,就会让人头大,有一肚子的牢骚要发:微软为什么不跟着国际标准走呢,总是独树一帜,搞出那么多问题来.IE的firebug调试工具也不太好用,尤其是低版本的IE,更是让人头疼. 最近 ...