Cod sursa(job #2494117)

Utilizator ezioconnorVlad - Gabriel Iftimescu ezioconnor Data 17 noiembrie 2019 13:10:48
Problema Mins Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>

using namespace std;

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

int c, d, n;
long long ans;
int ciur[1000001];
bool ciur2[1000001];

inline void compute(int i)
{
    if (!ciur[i])
    {
        for (int j = i; j <= n; j += i)
            ++ciur[j];
        long long k = 1LL * i * i;
        for (int j = k; j <= n; j += k)
            ciur2[j] = 1;
    }
    if (!ciur2[i])
    {
        long long k = 1LL * (c / i) * (d / i);
        if (ciur[i] & 1)
            ans += k;
        else
            ans -= k;
    }
}

int main()
{
    in >> c >> d;
    --c;
    --d;
    n = min(c, d);
    for (int i = 2; i <= n; ++i)
        compute(i);
    return out << 1LL * c * d - ans, 0;
}