CFdiv3之B. Squares and Cubes

这是链接

Polycarp likes squares and cubes of positive integers. Here is the beginning of the sequence of numbers he likes: 11, 44, 88, 99, ....

For a given number nn, count the number of integers from 11 to nn that Polycarp likes. In other words, find the number of such xx that xx is a square of a positive integer number or a cube of a positive integer number (or both a square and a cube simultaneously).

Input

The first line contains an integer tt (1≤t≤201≤t≤20) — the number of test cases.

Then tt lines contain the test cases, one per line. Each of the lines contains one integer nn (1≤n≤1091≤n≤109).

Output

For each test case, print the answer you are looking for — the number of integers from 11 to nn that Polycarp likes.

Example

input

Copy

6
10
1
25
1000000000
999999999
500000000

output

Copy

4
1
6
32591
32590
23125
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
typedef pair<int, int> P;
ll T;
int main()
{
    cin >> T;
    ll x;
    while (T--)
    {
        set<ll> st; // 一开始掉坑里
        cin >> x;
        for (ll i = 2; i * i <= x; i++)
        {
            st.insert(i * i);
            if (i * i * i <= x)
                st.insert(i * i * i);
        }
        if (!st.empty())
            cout << st.size() + 1 << endl;
        else
            cout << 1 << endl;
    }
}

题解:就是找小于给定数值有多少个平方和立方!我忽略了一个数可以既是平方或立方(比如说1000000),所以必须set去重

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值