ZOJ 3435 Ideal Puzzle Bobble (莫比乌斯反演基础题)

78 篇文章 0 订阅
56 篇文章 0 订阅


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 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);
    }
}




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值