Cod sursa(job #2460969)

Utilizator AlexandruabcdeDobleaga Alexandru Alexandruabcde Data 24 septembrie 2019 19:15:56
Problema Light2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream>
#include <algorithm>

using namespace std;

ifstream f ("light.in");
ofstream g ("light.out");

long long MAX;

int n;

long long d[30];

long long YEY (long long a, long long b)
{
    if (a==0) return b;
    else if (b==0) return a;
    else return a*b / __gcd(a, b);
}

long long PINEX_RECURSIV (int poz, int semn, long long val, long long MaxBit)
{
    if (val > MAX) val = MAX+1;

    if (poz == n)
    {
        if (val == 0) return 0;

        return MAX / val * MaxBit * semn;
    }
    else
    {
        return PINEX_RECURSIV(poz+1, semn, val, MaxBit) + PINEX_RECURSIV(poz+1, semn * (-1), YEY(val, d[poz]), MaxBit * 2);
    }
}

int main()
{
    f >> MAX >> n;

    for (int i=0; i<n; ++i)
        f >> d[i];

    g << PINEX_RECURSIV(0, -1, 0, 1) / 2 << '\n';
    return 0;
}