[ZOJ3435]Ideal Puzzle Bobble

题面戳我
题意:你现在处于\((1,1,1)\),问可以看见多少个第一卦限的整点。
第一卦限:就是\((x,y,z)\)中\(x,y,z\)均为正

sol

首先L--,W--,H--,然后答案就变成了
\[\sum_{i=1}^{L}\sum_{j=1}^{W}\sum_{k=1}^{H}[\gcd(i,j,k)==1]+\sum_{i=1}^{L}\sum_{j=1}^{W}[\gcd(i,j)==1]\]
\[+\sum_{i=1}^{L}\sum_{j=1}^{H}[\gcd(i,j)==1]+\sum_{i=1}^{W}\sum_{j=1}^{H}[\gcd(i,j)==1]+3\]
(加三是因为还有\((0,0,1),(0,1,0),(1,0,0)\)三个点)
所以直接做就行了。
第一个式子看上去有三个\(\sum\),但套路还是一样的,可以化成\[\sum_{i=1}^{\min(L,W,H)}\mu(i)\lfloor\frac Li\rfloor\lfloor\frac Wi\rfloor\lfloor\frac Hi\rfloor\]
数论分块走一波

code

#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
const int N = 1000000;
int pri[N+5],tot,zhi[N+5],mu[N+5],L,W,H;
void Mobius()
{
    zhi[1]=mu[1]=1;
    for (int i=2;i<=N;i++)
    {
        if (!zhi[i]) pri[++tot]=i,mu[i]=-1;
        for (int j=1;j<=tot&&i*pri[j]<=N;j++)
        {
            zhi[i*pri[j]]=1;
            if (i%pri[j]) mu[i*pri[j]]=-mu[i];
            else break;
        }
    }
    for (int i=1;i<=N;i++) mu[i]+=mu[i-1];
}
ll calc(int n,int m)
{
    int i=1;ll res=0;
    while (i<=n&&i<=m)
    {
        int j=min(n/(n/i),m/(m/i));
        res+=1ll*(n/i)*(m/i)*(mu[j]-mu[i-1]);
        i=j+1;
    }
    return res;
}
int main()
{
    Mobius();
    while (scanf("%d %d %d",&L,&W,&H)!=EOF)
    {
        L--,W--,H--;
        ll ans=0;int i=1;
        while (i<=L&&i<=W&&i<=H)
        {
            int j=min(L/(L/i),min(W/(W/i),H/(H/i)));
            ans+=1ll*(L/i)*(W/i)*(H/i)*(mu[j]-mu[i-1]);
            i=j+1;
        }
        printf("%lld\n",ans+calc(L,W)+calc(L,H)+calc(W,H)+3);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/zhoushuyu/p/8290056.html

时间: 2024-10-21 03:04:53

[ZOJ3435]Ideal Puzzle Bobble的相关文章

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 t

ZOJ3435_Ideal Puzzle Bobble

把L,H,W分别减一就变成上面一个题目了. 不多说,也不召唤代码君了. ZOJ3435_Ideal Puzzle Bobble

UVa - 227 - Puzzle

给空格子上下左右的互换操作,问最后是怎样的 注意一行的最后一个若是空格,需要自己加注意读取时 操作可能分好多行,一定要读取到 0 为止 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 char map[50][50],op[1000],c,tmp; 5 int k,t,x,y,cnt; 6 bool flag; 7 void fuc() 8 { 9 flag=1; 10 for(int i=0;

HDU 5465 Clarke and puzzle Nim游戏+二维树状数组

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 269 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 克拉克是一名人格分裂患者.某一天,有两个克拉克(aa和bb)在玩一个方格游戏. 这个方格是一个n*mn∗m的矩阵,每个格子里有一

HDU 1098 Ignatius&#39;s puzzle 费马小定理+扩展欧几里德算法

题目大意: 给定k,找到一个满足的a使任意的x都满足 f(x)=5*x^13+13*x^5+k*a*x 被65整除 推证: f(x) = (5*x^12 + 13 * x^4 + ak) * x 因为x可以任意取 那么不能总是满足 65|x 那么必须是 65 | (5*x^12 + 13 * x^4 + ak) 那么就是说 x^12 / 13 + x^4 / 5 + ak / 65 正好是一个整数 假设能找到满足的a , 那么将 ak / 65 分进x^12 / 13 + x^4 / 5中得到

HDU 4708 Rotation Lock Puzzle (贪心+模拟)

Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1668    Accepted Submission(s): 530 Problem Description Alice was felling into a cave. She found a strange door with a number

Dearboy&#39;s Puzzle (poj 2308 搜索 dfs+bfs)

Language: Default Dearboy's Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1202   Accepted: 208 Description Dearboy is a game lover. Recently, he loves playing the game Lian Lian Kan. This game is played on a board with N*M grids

hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Alice was felling into a cave. She found a strange door with a number square m

Aizu 0121 Seven Puzzle (康托展开+bfs)

Seven Puzzle Time Limit : 1 sec, Memory Limit : 65536 KB 7パズルは8つの正方形のカードとこれらのカードがぴたりと収まる枠を使って行います.それぞれのカードは互いに区別できるように.0,1,2....7と番号がつけられています.枠には.縦に2個.横に4個のカードを並べることができます. 7パズルを始めるときには.まず枠にすべてのカードを入れます.枠のなかで0のカードだけは.上下左右に隣接するカードと位置を交換することができます.たとえば.枠