Cod sursa(job #541511)

Utilizator Catah15Catalin Haidau Catah15 Data 25 februarie 2011 11:51:46
Problema Light2 Scor 10
Compilator cpp Status done
Runda Romanian Master in Mathematics and Sciences 2011, Ziua 1 Marime 0.67 kb
#include <fstream>

using namespace std;

#define MAXK 25
#define LL long long


LL k, n, e[MAXK], sol;


int main()
{
	ifstream f("light2.in");
	ofstream g("light2.out");
	
	f >> n;
	f >> k;
	
	for(int i = 1; i <= k; ++i)
		f >> e[i];
	
	
	sort(e + 1, e + k + 1);
	
	e[k + 1] = 0;
	
	int c = 1;
	
	for(int i = 1; i <= k; ++i)
	{
		if(e[i] == e[i + 1])
		{	
			++c;
			continue;
		}
		
		for(int j = e[i]; j <= n; j += e[i])
		{
			int cont = 0;
			
			for(int t = 1; t <= k; ++t)
				if( ! (j % e[t]) )
					++cont;
				
			if(cont % 2 && c % 2)
				++sol;
		}
		
		c = 1;
	}
	
	g << sol;
	
	f.close();
	g.close();
	
	return 0;
}