Cod sursa(job #2665916)

Utilizator hurjui12AlexandruHurjui Alexandru-Mihai hurjui12Alexandru Data 31 octombrie 2020 14:26:44
Problema Indep Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <fstream>
#include <vector>
using namespace std;

ifstream fin("indep.in");
ofstream fout("indep.out");

vector <int> dp[2][1001];

inline int gcd(int a, int b)
{
	int r;
	while (b)
	{
		r = a%b;
		a = b;
		b = r;
	}
	return a;
}

inline void adun(vector <int> &a, vector <int> &b)
{
	int i, x = 0, l = min(a.size(), b.size());
	for (i = 0; i<l; i++, x = x/10)
	{
		x = x + a[i] + b[i];
		a[i] = x%10;
	}
	for (i = a.size(); i < b.size(); i++, x = x/10)
	{
		x = x + b[i];
		a.push_back(x%10);
	}
	for (i = b.size(); i < a.size(); i++, x = x/10)
	{
		x = x + a[i];
		a[i] = x%10;
	}
	if (x)
		a.push_back(x);
}

int main()
{
	int x, n, i, j;
	
	fin >> n;
	dp[0][0].push_back(1);
	for (i = 1; i<=n; i++)
	{
		fin >> x;
		for (j = 0; j<=1000; j++)
			dp[i&1][j] = dp[(i&1)^1][j];
		for (j = 0; j<=1000; j++)
			if (dp[(i&1)^1][j].empty() == 0)
				adun(dp[i&1][gcd(j, x)], dp[(i&1)^1][j]);
	}
	if (dp[n&1][1].empty() == 0)
		for (i = dp[n&1][1].size()-1; i>=0; i--)
			fout << dp[n&1][1][i];
	else
		fout << 0;
	return 0;
}