Cod sursa(job #1982442)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 18 mai 2017 20:15:15
Problema Mins Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 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;

    for (int i = 2; i <= min(c, d); ++ i) {
        if (o[ i ] == 1) continue;

        int x = (1 - o[ i ]);
        for (int j = i; j <= min(c, d); j += i) {
            o[ j ] += x;
        }

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

    fout << ans << "\n";

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