ZOJ 3435 Ideal Puzzle Bobble (莫比烏斯反演基礎題)
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 andH 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 crushall the colorful bubbles in the straight line which the magical bubble flies every single time. Note that bubbles aresignificantly 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 integersL, 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
題目連結:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3435
題目大意:(1,1,1)和(l, w, h)組成的長方體中從點(1,1,1)能看到的點數
題目分析:和前一題幾乎一樣,唯一的不同就是gcd(a, b, c) = 1,1 <= a <= l,1 <= b <= w,1 <= c <= h,範圍不同,然而這並沒有什麼卵關係,l,w,h都減1,函式的引數變一下就行了
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
int const MAX = 1000005;
int mob[MAX], p[MAX], sum[MAX];
bool noprime[MAX];
int Min(int a, int b, int c)
{
return min(a, min(b, c));
}
void Mobius()
{
int pnum = 0;
mob[1] = 1;
sum[1] = 1;
for(int i = 2; i < MAX; i++)
{
if(!noprime[i])
{
p[pnum ++] = i;
mob[i] = -1;
}
for(int j = 0; j < pnum && i * p[j] < MAX; j++)
{
noprime[i * p[j]] = true;
if(i % p[j] == 0)
{
mob[i * p[j]] = 0;
break;
}
mob[i * p[j]] = -mob[i];
}
sum[i] = sum[i - 1] + mob[i];
}
}
ll cal(int l, int r)
{
if(l > r)
swap(l, r);
ll ans = 0;
for(int i = 1, last = 0; i <= l; i = last + 1)
{
last = min(l / (l / i), r / (r / i));
ans += (ll) (l / i) * (r / i) * (sum[last] - sum[i - 1]);
}
return ans;
}
ll cal(int l, int m, int r)
{
if(l > r)
swap(l, r);
if(l > m)
swap(l, m);
ll ans = 0;
for(int i = 1, last = 0; i <= l; i = last + 1)
{
last = Min(l / (l / i), m / (m / i), r / (r / i));
ans += (ll) (l / i) * (m / i) * (r / i) * (sum[last] - sum[i - 1]);
}
return ans;
}
int main()
{
Mobius();
int a, b, c;
while(scanf("%d %d %d", &a, &b, &c) != EOF)
{
a --;
b --;
c --;
ll ans = 3;
ans += (ll) cal(a, b, c);
ans += (ll) cal(a, b);
ans += (ll) cal(b, c);
ans += (ll) cal(a, c);
printf("%lld\n", ans);
}
}
相關文章
- 莫比烏斯反演
- 比較典的莫比烏斯反演
- Hackerrank GCD Product(莫比烏斯反演)GC
- 莫比烏斯反演學習筆記筆記
- Problem H. Curious (莫比烏斯反演)
- 狄利克雷卷積 & 莫比烏斯反演卷積
- 狄利克雷卷積與莫比烏斯反演卷積
- 莫比烏斯
- cf900D. Unusual Sequences(容斥 莫比烏斯反演)
- 洛谷 P2257 YY的GCD(莫比烏斯反演)GC
- 演算法隨筆——數論之莫比烏斯反演演算法
- SDOI2018 舊試題(莫比烏斯反演+三元環計數)
- SDOI2018 反迴文串(莫比烏斯反演+Pollard-Rho)
- 莫比烏斯函式函式
- 莫比烏斯函式 - 學習筆記函式筆記
- 基礎莫隊模板
- 【莫煩】python基礎教程Python
- 基礎莫隊演算法演算法
- 題解:CF634A Island Puzzle
- zoj
- CF613E Puzzle Lover 題解
- CF1990D Grid Puzzle 題解
- 題解 CF613E Puzzle Lover
- CatGPT PuzzleGPT
- [ABC347C] Ideal Holidays題解Idea
- 基礎題
- 2018世界盃烏拉圭vs俄羅斯誰會贏 烏拉圭vs俄羅斯比分預測
- Java基礎題Java
- python基礎題Python
- 基礎題二
- 基礎題一
- C - Ideal HolidaysIdea
- ideal 快捷鍵Idea
- 基於Google earth engine python API做基於影像的定量反演——步驟及問題總結GoPythonAPI
- 猿人學web端爬蟲攻防大賽賽題第19題——烏拉烏拉烏拉Web爬蟲
- 薩繆爾·莫爾斯:電報之父的傳奇人生
- 一道比較少見的基礎面試題,考考大家面試題
- ZOJ Monthly, March 2018
- ZOJ 3732 Graph ReconstructionStruct