A Simple Math Problem

A Simple Math Problem

题目大意

A Simple Math Problem

输入描述

A Simple Math Problem

输出描述

A Simple Math Problem

样例

输入

3

输出

5

推导
A Simple Math Problem

#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e6+1;

int prime[maxn], mu[maxn], phi[maxn], tot;
bool vis[maxn];
int f[maxn];

void get_pmp(int n) {
    vis[1] = mu[1] = phi[1] = 1;
    for(int i = 2; i <= n; ++ i) {
        if (!vis[i]) {
            prime[++tot] = i;
            mu[i] = -1;
            phi[i] = i-1;
        }
        for(int j = 1; prime[j] <= n/i; ++ j) {
            vis[prime[j]*i] = 1;
            phi[prime[j]*i] = prime[j] * phi[i];
            if (i % prime[j] == 0) break;
            mu[prime[j]*i] = mu[prime[j]] * mu[i];
            phi[prime[j]*i] = phi[prime[j]] * phi[i];
        }
    }
}

void get_f(int n) {
    for(int i = 1; i <= n; ++ i) {
        int t = i;
        while(t) {
            f[i] += t%10;
            t /= 10;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    get_pmp(n);
    get_f(n);
    long long res = 1;
    for(int i = 1; i <= n; ++ i) {
        long long t = 0;
        for(int j = 1; j <= n/i; ++ j) {
            t += f[j*i];
        }
        res += mu[i] * n/i * t - phi[i] * f[i];
    }
    cout << res << "\n";
    return 0;
}

代码

上一篇:Solution Of My Contest:playing with 毛玉


下一篇:FOC矢量控制及仿真