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> ...
随机推荐
- 转 linux 权限
发布系统架构图简化如下: 管理员通过Jenkins调用“发布程序(代号varian,以下简称varian)”,发布程序会进行一系列的初始化操作,完成后生成Docker镜像上传到Docker仓库,容器集 ...
- UNIX环境编程学习笔记(10)——文件I/O之硬链接和符号链接
lienhua342014-09-15 1 文件系统数据结构 UNIX 文件系统通过 i 节点来存储文件的信息.如图 1 所示为一个磁盘柱面上的 i 节点和数据块示意图.其中 i 节点是一个固定长度的 ...
- pytest集成Allure Report
https://blog.csdn.net/liuchunming033/article/details/79624474#commentBox https://blog.csdn.net/lihua ...
- ul li列表元素浮动导致border没有底边解决办法
如图,当ul li,li元素浮动,并且ul元素也overflow:hidden清除浮动的时候,给li元素加了border,但是不显示底边,这时候要看是不是没有给li元素加高,因为加了border之后默 ...
- Unity判断网络是否连接以及判断是否连接WiFi
由于项目中的核心模块需要用到网络连接,所以需要首先检测用户是否有网络百度了下,有人说通过连接自己的服务器进行测试的,也有人说通过延迟来判断的最后发现原来Unity是提供了网络判断的方法的.Networ ...
- JSON未定义
用ajax实现了一个功能,在IE8和IE9中都能正常运行(大概是IE8和IE9都提供了原生的JSON解析和序列化),但是一旦切换到兼容模式就报JSON未定义的错误,解决方法是:判断当前浏览器是否支持J ...
- webdriver+expected_conditions二次封装
结合这两种方法对代码做二次封装,可以提升脚本性能 例: #coding:utf-8 #封装元素方法from selenium import webdriverfrom selenium.webdriv ...
- iOS AppsFlyer的使用注意事项
AppFlyer 是近期比較火的一款广告追踪统计工具,当然统计的功能友盟也能够实现,而appsflyer更是具有定向投放,是app跳转到对应的页面. 详细的:当点击广告的时候,假设没有安装应用.则会跳 ...
- PMP模拟考试-2
1. Increasing resources on the critical path activities may not always shorten the length of the pro ...
- flexbox子盒子flex属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...