Cod sursa(job #1982444)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 18 mai 2017 20:17:23
Problema Mins Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>

using namespace std;

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

const int nmax = 1e6;

int o[nmax + 1];

int main() {
    int c, d;

    fin >> c >> d;
    -- c, -- d;

    long long ans = 1LL * c * d;

    int lim = min(c, d);

    for (int i = 2; i <= lim; ++ i) {
        if (o[ i ] == 1) continue;

        int x = (1 - o[ i ]);
        for (int j = 2 * i; j <= lim; j += i) {
            o[ j ] += x;
        }

        ans -= 1LL * x * (c / i) * (d / i);
    }

    fout << ans << "\n";

    fin.close();
    fout.close();
    return 0;
}