Cod sursa(job #541746)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 25 februarie 2011 13:52:34
Problema Light2 Scor 0
Compilator cpp Status done
Runda Romanian Master in Mathematics and Sciences 2011, Ziua 1 Marime 0.93 kb
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define sh short int
#define LL long long
#define pb push_back
int v[25],a[25];
LL N,ap;
sh K;
inline void unic()
{
	int x=v[1];
	int num=1;
	for (int i=2; i<=K; ++i)
	{
		if (v[i]==v[i-1])
			++num;
		else
		{
			if (num&1)
				a[++a[0]]=x;
			x=v[i];
			num=1;
		}
	}
	if (num&1)
		a[++a[0]]=x;
}
inline void citire()
{
	freopen("light2.in","r",stdin);
	freopen("light2.out","w",stdout);
	scanf("%lld%hd",&N,&K);
	for (sh i=1; i<=K; ++i)
		scanf("%d",&v[i]);
	sort(v+1,v+1+K);
	unic();
}
inline void light()
{
	sh num;
	bool ok;
	for (LL i=a[1]; i<=N; )
	{
		ok=true;
		num=0;
		for (sh j=1; j<=a[0]; ++j)
		{
			if (i<a[j])
			{
				i=a[j];
				ok=false;
				break;
			}
			if (i%a[j]==0)
				++num;
		}
		i+=ok;
		ap+=(num&1);
	}
	printf("%lld",ap);
	
}
int main()
{
	citire();
	light();
	return 0;
}