题意
Sol
min25筛的板子题,直接筛出\(g(N, \infty)\)即可
筛的时候有很多trick,比如只存\(\frac{N}{x}\)的值,第二维可以滚动数组滚动掉
#include<bits/stdc++.h>
#define LL long long
//#define int long long
using namespace std;
const int MAXN = 2e6 + 10;
int Lim, vis[MAXN], prime[MAXN], tot;
LL N, g[MAXN], id[MAXN], cnt, pos1[MAXN], pos2[MAXN];
void Get(int N) {
vis[1] = 1;
for(int i = 2; i <= N; i++) {
if(!vis[i]) prime[++tot] = i;
for(int j = 1; j <= tot && i * prime[j] <= N; j++) {
vis[i * prime[j]] = 1;
if(!(i % prime[j])) break;
}
}
}
LL get(LL x) {
return x <= Lim ? pos1[x] : pos2[N / x];
}
signed main() {
cin >> N; Lim = sqrt(N);
Get(Lim);
for(LL i = 1, j; i <= N; i = N / j + 1) {
j = N / i; id[++cnt] = j; g[cnt] = id[cnt] - 1;
j <= Lim ? pos1[j] = cnt : pos2[N / j] = cnt;;
}
for(int j = 1; j <= tot; j++)
for(LL i = 1; 1ll * prime[j] * prime[j] <= id[i]; i++)
g[i] -= g[get(id[i] / prime[j])] - (j - 1);
cout << g[1];
return 0;
}