You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.7 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
2 years ago
#define int long long
#define endl "\n"
const int N = 110;
2 years ago
2 years ago
/*
2 years ago
2 years ago
2 years ago
mu ****
mu[i]
2 years ago
2 years ago
1na^ba,b0b1
nx^2 pow(n,1/2)
nx^3 pow(n,1/3)
x^6 (x^2)^3 (x^3)^2
nx^6,pow(n,1/6)
2 years ago
15MS
2 years ago
*/
2 years ago
// 筛法求莫比乌斯函数
2 years ago
int mu[N], primes[N], cnt;
2 years ago
bool st[N];
2 years ago
void get_mobius(int n) {
2 years ago
mu[1] = 1;
2 years ago
for (int i = 2; i <= n; i++) {
2 years ago
if (!st[i]) {
primes[cnt++] = i;
2 years ago
mu[i] = -1;
}
2 years ago
for (int j = 0; primes[j] <= n / i; j++) {
int t = primes[j] * i;
2 years ago
st[t] = true;
2 years ago
if (i % primes[j] == 0) {
mu[t] = 0;
2 years ago
break;
}
2 years ago
mu[t] = -mu[i];
2 years ago
}
}
}
2 years ago
2 years ago
signed main() {
2 years ago
// 筛法求莫比乌斯函数
2 years ago
get_mobius(N - 1);
2 years ago
int n;
while (cin >> n) {
2 years ago
int s = 1;
2 years ago
// 对于1e18次方的话最多就是2的64次方,逐个枚举2的i次方
for (int i = 2; i <= 64; i++)
s -= mu[i] * (int)(pow(n, 1.0 / i) - 1);
2 years ago
cout << s << endl;
2 years ago
}
}