Cod sursa(job #3299378)

Utilizator rapidu36Victor Manz rapidu36 Data 5 iunie 2025 19:29:45
Problema Mins Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <fstream>
#include <vector>

using namespace std;

void ciur(int n, vector <int> &pdp, vector <int> &nrdp)
{
    for (int d = 2; d <= n; d++)
    {
        if (nrdp[d] == 0)
        {
            for (int m = d; m <= n; m += d)
            {
                pdp[m] *= d;
                nrdp[m]++;
            }
        }
    }
}

int main()
{
    ifstream in("mins.in");
    ofstream out("mins.out");
    int c, d;
    in >> c >> d;
    c--;
    d--;
    int n = max(c, d);
    vector <int> pdp(n + 1, 1);
    vector <int> nrdp(n + 1, 0);
    ciur(n, pdp, nrdp);
    long long suma = 0;
    for (int i = 1; i <= n; i++)
    {
        if (pdp[i] == i)
        {
            long long termen = (long long)c / i;
            termen *= d / i;
            if (nrdp[i] % 2 == 0)
            {
                suma += termen;
            }
            else
            {
                suma -= termen;
            }
        }
    }
    out << suma << "\n";
    in.close();
    out.close();
    return 0;
}