[luogu p7464] [CERC2018] The Silence of the Lamps

洛谷 P7464 [CERC2018] The Silence of the Lamps

Link\mathtt{Link}

P7464 [CERC2018] The Silence of the Lamps - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

Description\mathtt{Description}

TT 组多测。

给定一个数 nn,求满足以下条件的三元正整数组 (i,j,k)(i, j, k) 的数量:

  • 0<i<j<kn0 < i < j < k \le n

  • i×j×kni \times j \times k \le n

Data Range & Restrictions\mathtt{Data} \text{ } \mathtt{Range} \text{ } \mathtt{\&} \text{ } \mathtt{Restrictions}

  • 1T1051 \le T \le 10^5
  • 1n1061 \le n \le 10^6

Solution\mathtt{Solution}

为什么不 % 1e9 + 7

发现本题中的三元组合法性满足包含关系,举个例子:n=8n = 8 时合法的三元组一定包含 n=5n = 5 时合法的三元组。

因此首先考虑将询问离线下来,对每个 gg 求出 i×j×k=gi \times j \times k = g 的三元组数量,进行前缀和,直接回答询问。

复杂度无法承受。考虑逆向思维,暴力枚举 i,j,ki, j, k,采用桶计数的思想,将 i×j×ki \times j \times k 对应的桶自增1。

然后这个题就做完了。

Time Complexity\mathtt{Time} \text{ } \mathtt{Complexity}

不会求,感觉大概 O(nlog3n)\operatorname{O}(n \log ^3n)?(嘴的)

Code\mathtt{Code}

/*
 * @Author: crab-in-the-northeast 
 * @Date: 2022-05-04 12:34:28 
 * @Last Modified by: crab-in-the-northeast
 * @Last Modified time: 2022-05-04 12:46:55
 */
#include <iostream>
#include <cstdio>
#include <cmath>
inline int read() {
    int x = 0;
    bool flag = true;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-')
            flag = false;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 1) + (x << 3) + ch - '0';
        ch = getchar();
    }
    if(flag) return x;
    return ~(x - 1);
}

const int maxn = 1e6 + 5;
int a[maxn];

int main() {
    int T = read();
    for (int i = 1; i < cbrt(maxn); ++i)
        for (int j = i + 1; j <= maxn / i; ++j)
            for (int k = j + 1; k <= maxn / i / j; ++k)
                ++a[i * j * k];
    for (int i = 2; i <= maxn; ++i)
        a[i] += a[i - 1];
    while (T--) {
        int x = read();
        printf("%d\n", a[x]);
    }
    return 0;
}
posted @   dbxxx  阅读(82)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示