题解:P5589 小猪佩奇玩游戏
简单题。
我们考虑一个数 map 存储。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
#define inf 0x3f3f3f3f
#define Inf 0x3f3f3f3f3f3f3f3fll
ll n;
map<int,int> mp;
inline void Solve()
{
cin >> n;
mp.clear();
for(int i=2;pow(2ll,i)<=n;i++)
{
ll now=2;
while(pow(now,i)<=n) mp[pow(now++,i)]++;
}
double ans=n;
for(auto [x,y]:mp) ans=ans-1+1.0/(y+1);
printf("%.4lf\n",ans);
}
int main()
{
// int t=clock();
// freopen("gdx.in","r",stdin);
// freopen("gdx.out","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
// int Type;
// cin >> Type;
int T;
cin >> T;
while(T--)
Solve();
// cerr << clock()-t << '\n';
return 0;
}