示例#1
0
static void solve(u32 n) {
    Erato erato(n + 100);
    u64 result = 0;
    for (u32 i = 2; i <= n; ++i) {
        if (0 == (i % 1000000)) {
            cerr << "..." << i << endl;
        }

        auto factors = factorization(i, erato);
        u64 iResult = 1;
        for (auto& factor: factors) {
            u64 number = factor.factor_;
            i64 power = factor.power_;
            u64 mult = 0;
            while (power > 0) {
                mult += number;
                auto now = mult;
                while (now != 0 && 0 == (now % number)) {
                    now /= number;
                    --power;
                }
            }
            iResult = std::max(iResult, mult);
        }
        result += iResult;
    }
    cout << n << " " << result << endl;
}
示例#2
0
void solve(u64 n) {
    Erato erato(n/6 + 10);

    u64 result = 0;
    const auto& primes = erato.primes_;
    for (size_t i = 0; i < primes.size(); ++i) {
        u64 p1 = primes[i];

        auto toP2 = upper_bound(primes.begin(), primes.end(), pow(static_cast<long double>(n/p1), 1.0/3));
        if (toP2 > primes.begin() + i) {
            result += toP2 - primes.begin() - i - 1;
        }

        toP2 = upper_bound(primes.begin(), primes.end(), n/p1/p1/p1);
        if (toP2 > primes.begin() + i) {
            result += toP2 - primes.begin() - i - 1;
        }

        for (size_t j = i + 1; j < primes.size(); ++j) {
            u64 p2 = primes[j];
            u64 p3Limit = n/p1/p2;
            if (p3Limit > p2) {
                auto toP3 = upper_bound(primes.begin(), primes.end(), p3Limit);
                if (toP3 > primes.begin() + j) {
                    result += toP3 - primes.begin() - j - 1;
                }
            }
        }
    }

    u64 limit8 = pow(static_cast<long double>(n), 1./7);
    result += upper_bound(primes.begin(), primes.end(), limit8) - primes.begin();

    cout << n << " " << result << endl;
}