Cod sursa(job #500203)

Utilizator Teodor94Teodor Plop Teodor94 Data 11 noiembrie 2010 18:26:00
Problema Indep Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 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][2*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 scrie()
{
	for(int i=1 ; i<=n ; ++i)
	{
		for(int j=1 ; j<=12 ; ++j)
			printf("%8d",mat[i][j]);
		printf("\n");
	}
}

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

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