隐藏页面特效

ZOJ 3435 Ideal Puzzle Bobble

ZOJ Problem Set - 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 (xyz) to represent the locations of the bobble dragon and those bubbles. All these coordinates (xyz) are triple positive integers ranged from (111) to (LWH).

To simplify the problem, let's assume the bobble dragon is standing at (111) in the room. And there is one colorful bubble at every (xyz) in the room except (111). 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 LW 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+5; int L,W,H,T;ll sum[M]; int tot,prime[M/3],mu[M];bool check[M]; void sieve(){ int n=1e6;mu[1]=1; for(int i=2;i<=n;i++){ if(!check[i]) prime[++tot]=i,mu[i]=-1; for(int j=1;j<=tot&&i*prime[j]<=n;j++){ check[i*prime[j]]=1; if(!(i%prime[j])){mu[i*prime[j]]=0;break;} else mu[i*prime[j]]=-mu[i]; } } for(int i=1;i<=n;i++) sum[i]=sum[i-1]+mu[i]; } inline ll solve(int x,int y,int z){ int t=min(x,min(y,z)); ll ans=3; for(int i=1,pos;i<=t;i=pos+1){ pos=min(x/(x/i),min(y/(y/i),z/(z/i))); ans+=1LL*(x/i)*(y/i)*(z/i)*(sum[pos]-sum[i-1]); } t=min(x,y); for(int i=1,pos;i<=t;i=pos+1){ pos=min(x/(x/i),y/(y/i)); ans+=1LL*(x/i)*(y/i)*(sum[pos]-sum[i-1]); } t=min(y,z); for(int i=1,pos;i<=t;i=pos+1){ pos=min(y/(y/i),z/(z/i)); ans+=1LL*(y/i)*(z/i)*(sum[pos]-sum[i-1]); } t=min(x,z); for(int i=1,pos;i<=t;i=pos+1){ pos=min(x/(x/i),z/(z/i)); ans+=1LL*(x/i)*(z/i)*(sum[pos]-sum[i-1]); } return ans; } int main(){ sieve(); while(~scanf("%d%d%d",&L,&W,&H)){ L--,W--,H--; printf(LL"\n",solve(L,W,H)); } return 0; }

 


__EOF__

本文作者shenben
本文链接https://www.cnblogs.com/shenben/p/6750052.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   神犇(shenben)  阅读(302)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
点击右上角即可分享
微信分享提示