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去重!