Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.1 kB
2
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;
bool b[maxn];
long long sum , res;
vector<int> v ;

bool check(int a){
    for(int i = 0 ; i < v.size() ; i++){
        if(a % v[i] == 0){
            sum++;
            a/=v[i];
        }
    }
   
    if(a == 1) return true;
    return false ;
}
int mobius(int a){
    b[1] = 1;
    int ans = sqrt(a);
    for(int i = 2 ; i <= ans ; i++){
        if(b[i] == 0){
            for(int j = i*i ; j <= a ; j+= i){
                b[j] == 1;
                v.push_back(i);
            }
        }
    }
    for(int i = ans+1 ; i <= a ; i++){
        if(b[i] == 0){
            v.push_back(i);
        }
    }
    if(!check(a)) return 0;
    else if(sum % 2 == 0) return 1;
    else return -1;
     
}
int main(){
    ios;
    int a ;
    cin >> a;
    for(int i = 2 ; i <= a ; i++){
        sum = 0 ;
        v.clear() ;
        res += mobius(i) * pow(a/i , 2);
    }
    cout << a*a + res;

    return 0;
}