abc179_c - Axb+C

Click to show code.


using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using mii = map<int, int>;
const int NMAX = 1e7 + 11;
bitset<NMAX> is_prime;
vector<int> primes;
mii prime_factors(ll n)
{
    mii factors;
    ll i = 0, pf = primes[i];
    while (pf * pf <= n)
    {
        while (n % pf == 0)
        {
            ++factors[pf];
            n = n / pf;
        }
        pf = primes[++i];
    }
    if (n != 1)
        ++factors[n];
    return factors;
}
void sieve(ll sieve_size)
{
    is_prime.set();
    is_prime[0] = is_prime[1] = 0;
    for (ll i = 2; i <= sieve_size; i++)
        if (is_prime[i])
        {
            for (ll j = i * i; j <= sieve_size; j += i)
                is_prime[j] = 0;
            primes.push_back((int)i);
        }
}
int main(void)
{
    int n;
    cin >> n;
    sieve(NMAX);
    ll ans = 0;
    for (int x = 1; x < n; ++x)
    {
        ll cur = 1;
        auto factors = prime_factors(x);
        for (auto [k, v] : factors)
            cur *= v + 1;
        ans += cur;
    }
    cout << ans << endl;
    return 0;
}