Cod sursa(job #500040)

Utilizator Teodor94Teodor Plop Teodor94 Data 11 noiembrie 2010 11:26:19
Problema Indep Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
// mat[i][j]=cate subsiruri se pot forma din primele i cu cmmdc j
#include<cstdio>

const int N=505;

int n,a[N],mat[N][N];

void citire()
{
	freopen("indep.in","r",stdin);
	freopen("indep.out","w",stdout);
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
		scanf("%d",&a[i]);
}

int cmmdc(int x,int y)
{
	int r;
	while (y)
	{
		r=x%y;
		x=y;
		y=r;
	}
	return x;
}

void dinamica()
{
	mat[1][a[1]]=1;
	for (int i=2;i<=n;++i)
		for (int j=1;j<=1000;++j)
			mat[i][cmmdc(j,a[i])]=mat[i-1][j]+mat[i-1][cmmdc(j,a[i])];
	printf("%d\n",mat[n][1]);
}

int main()
{
	citire();
	dinamica();
	return 0;
}