>
Codeforces - 1619B. Squares and Cubes
2022-01-29 题解 162 字

一道简单的 set 练习题。

**解题思路:**从 11n\sqrt{n} 循环筛一下 完全平方数,再从 11n3\sqrt[3]{n} 循环筛一下 完全立方数,去掉重复的数字,然后输出 size

为了方便去重,我们用 set 来存储筛出的数。

Code:

#include <iostream>
#include <cmath>
#include <set>

int t, n;

int main()
{
    std::cin >> t;
    while (t--)
    {
        std::cin >> n;
        std::set <int> table;
        for (int i = 1; i * i <= n; i ++ ) table.insert(i * i);
        for (int i = 1; i * i * i <= n; i ++ ) table.insert(i * i * i);
        std::cout << table.size() << std::endl;
    }
    return 0;
}

题目信息

难度 入门
链接 CF1619B
来源 Codeforces
Codeforces - 1619B. Squares and Cubes
本文作者
Sky390
发布于
2022-01-29
版权协议
转载或引用本文时请遵守许可协议,注明出处、不得用于商业用途!