CF1619B Squares and Cubes 题解
and 题解
2023-06-13 09:12:17 时间
这道题就是容易想复杂,其实想明白很简单。
我的思路是,从 1 到 \sqrt{n} 循环筛一下 完全平方数,再从 1 到 \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;
}
相关文章
- 【说站】memcached安装失败 提示make: *** No targets specified and no makefile found. Stop.
- MIT 6.828 操作系统工程 Lab5: File system, Spawn and Shell 笔记
- odoo 开发入门教程系列-计算的字段和变更(Computed Fields And Onchanges)
- ORA-01586: database must be mounted EXCLUSIVE and not open for this operation ORACLE 报错 故障修复 远程处理
- ORA-02225: only EXECUTE and DEBUG privileges are valid for procedures ORACLE 报错 故障修复 远程处理
- ORA-15258: user group entry number must be between string and string, inclusive ORACLE 报错 故障修复 远程处理
- ORA-16112: log mining and apply stopping ORACLE 报错 故障修复 远程处理
- oracle ora-00054:resource busy and acquire with nowait specified解决方法
- Exploring GID in Linux: Understanding Group ID and its Importance in System Security and Management(linuxgid)
- Mastering Linux Configuration with C Programming and INI Files(linuxcini)
- Mysql中强大的AND运算符的使用方法探究(mysql中and的使用)
- php中OR与||AND与&&的区别总结