Cod sursa(job #360973)

Utilizator undogSavu Victor Gabriel undog Data 3 noiembrie 2009 08:41:21
Problema Indep Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <cstdio>

int ggt(int a,int b){
	int aux;
	while(b){
		 aux=a%b;
		 a=b;
		 b=aux;
	}
	return a;
}


int main(){
	freopen("indep.in","rt",stdin);
	freopen("indep.out","wt",stdout);
	
	int n,v[500];
	scanf("%d",&n);
	
	int i,j;
	for(i=0;i<n;i++)
		scanf("%d",&v[i]);
	
	int d[500],c[500];
	int ct,min,aux;
	
	d[0]=v[0];
	if(v[0]==1)
		c[0]=1;
	else
		c[0]=0;
	
	for(i=1;i<n;i++){
		min=v[i];
		ct=0;
		for(j=0;j<i;j++){
			aux=ggt(v[i],d[j]);
			if(aux<min){
				min=aux;
				if(c[j]==0)
					ct=1;
				else
					ct=c[j];
			}
			else if(aux==min)
				if(c[j]==0)
					ct+=1;
				else
					ct+=c[j];
		}
		d[i]=min;
		if(ct==0&min==1)
			c[0]=1;
		else
			c[j]=ct;
	}
	ct=0;
	for(i=0;i<n;i++)
		if(d[i]==1)
			ct+=c[i];
	printf("%d",ct);
}