Cod sursa(job #1766016)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 27 septembrie 2016 11:50:25
Problema Dosare Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

ifstream fin("ndiv.in");
ofstream fout("ndiv.out");

int v[100005];
inline long long Solve(int n) {

    size_t sz = 0;
    for (int i = 1; 1LL * i * i <= 1LL * n; ++i) {
        v[sz++] = i;
        if (n/i != i)
            v[sz++] = n/i;
    }

    sort(v, v + sz);
    reverse(v, v + sz);

    long long ret = n;
    for (size_t i = 0, j = 1; j < sz; ++i, ++j) {
        ret += 1LL * (n/v[i])*(v[i] - v[j]);
    }

    return ret;

}

int main() {

    int a, b;
    fin >> a >> b;

    fout << Solve(b) - Solve(a - 1) << '\n';

    return 0;

}

//Trust me, I'm the Doctor!