Untitled
unknown
c_cpp
2 years ago
899 B
7
Indexable
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
using namespace std ;
const int maxn = 1e6+7;
int total = 1e6+7;
long long sum = 1, res;
vector<int> v[maxn];
int v2[maxn];
void mobius(int a){
for(int i = 2 ; i <= total ; i++){
if(v[i].size() == 0){
for(int j = i ; j <= total ; j+= i){
v[j].push_back(i);
}
}
}
for(int i = 0 ; i <= a ; i++){
sum = 1 ;
for(int j = 0 ; j < v[i].size() ; j++){
sum *= v[i][j] ;
}
if(sum != i) v2[i] = 0;
else if(v[i].size() % 2 == 0) v2[i] = 1;
else v2[i] = -1;
}
}
int main(){
ios;
int a ;
cin >> a;
mobius(a);
for(int i = 2 ; i <= a ; i++){
res += v2[i] * pow(a/i , 2);
}
cout << a*a + res;
return 0;
}Editor is loading...