题目:经过提炼后, 题目的意思就是问[2,n] 内,不是次方数的数量 ,;
思路:
答案就是
原理是利用容斥,注意n开i次根是向下取整(这题巨卡精度)
这是大神的思路 ,, 我还没有理解, 先放着,等以后在来思考 , 先当模板使用
#include <bits/stdc++.h> #define forn(i, n) for (int i = 0; i < int(n); i++) using namespace std; const int K = ;
const int N = * + ;
const long long INF64 = 3e18; int mu[K]; void precalc(){
static bool prime[K];
static int lst[K]; memset(prime, false, sizeof(prime));
forn(i, K) lst[i] = i; for (int i = ; i < K; ++i){
if (lst[i] == i) mu[i] = ;
for (int j = * i; j < K; j += i){
lst[j] = min(lst[j], lst[i]);
if (lst[j] == lst[i])
mu[j] = ;
else
mu[j] = -mu[i];
}
}
} int mx[K]; long long binpow(long long a, int b){
long long res = ;
while (b){
if (b & ){
if (res < INF64 / a) res *= a;
else return INF64;
}
if (b > ){
if (a < INF64 / a) a *= a;
else return INF64;
}
b >>= ;
}
return res;
} long long calc(long long n){
int pw = - __builtin_clzll(n);
for (int i = ; i <= pw; ++i){
if (mu[i] == ) continue;
while (binpow(mx[i], i) > n)
--mx[i];
} long long res = n - ;
for (int i = ; i <= pw; ++i)
res -= mu[i] * (mx[i] - ); return res;
} int get_sqrt(long long n){
int l = , r = ;
while (l < r - ){
int m = (l + r) / ;
if (m * 1ll * m <= n)
l = m;
else
r = m;
}
return (r * 1ll * r <= n ? r : l);
} long long ans[N]; int main() {
precalc();
int T;
scanf("%d", &T);
vector<pair<long long, int> > q; forn(i, T){
long long n;
scanf("%lld", &n);
q.push_back({n, i});
} sort(q.begin(), q.end(), greater<pair<long long, int> >());
mx[] = ;
mx[] = ;
mx[] = ;
for (int i = ; i < K; ++i)
mx[i] = ; forn(z, T){
long long n = q[z].first;
mx[] = get_sqrt(n);
ans[q[z].second] = calc(n);
} forn(i, T)
printf("%I64d\n", ans[i]);
return ;
}