>
一道简单的 set
练习题。
**解题思路:**从 到 循环筛一下 完全平方数,再从 到 循环筛一下 完全立方数,去掉重复的数字,然后输出 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 |