Pagini recente » Cod sursa (job #1179828) | Cod sursa (job #1232289) | Cod sursa (job #2502134) | Cod sursa (job #1696753) | Cod sursa (job #2460969)
#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;
}