Educational Codeforces Round 50: F. Relatively Prime Powers(莫比乌斯函数)
程序员文章站
2022-06-04 09:24:43
...
F. Relatively Prime Powers
题意:
给你一个n,问满足在[2,n]范围内有多少个数是非次方数(也就是不是这样的)
思路:
答案就是
原理是利用容斥,注意n开i次根是向下取整(这题巨卡精度)
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
#define LL long long
#define LD long double
#define mod 1000000007
int cnt, flag[105] = {1,1}, pri[105], mu[105] = {0,1};
LL sum[105];
void Mulset()
{
int i, j;
for(i=2;i<=105;i++)
{
if(flag[i]==0)
{
pri[++cnt] = i;
mu[i] = -1;
}
for(j=1;j<=cnt&&i*pri[j]<=105;j++)
{
flag[i*pri[j]] = 1;
if(i%pri[j]==0)
{
mu[i*pri[j]] = 0;
break;
}
mu[i*pri[j]] = -mu[i];
}
}
}
int main(void)
{
LL ans, n;
int T, i;
Mulset();
scanf("%d", &T);
while(T--)
{
ans = 0;
scanf("%lld", &n);
for(i=2;i<=60;i++)
{
sum[i] = (LL)powl((LD)n+0.1, (LD)1.0/i)-1;
ans += sum[i]*mu[i];
}
printf("%lld\n", n-1+ans);
}
return 0;
}