Cod sursa(job #160827)

Utilizator alextheroTandrau Alexandru alexthero Data 16 martie 2008 23:14:26
Problema Indep Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <stdio.h>

#define nmax 505
#define vmax 1005

int n, now;
int a[nmax];
int c[2][vmax];

int cmmdc(int a, int b)
{
	if(b == 0) return a;
	else return cmmdc(b, a % b);
}

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

	c[1][a[1]] = 1; now = 0;
	for(int i = 1; i < n; i++)
	{
		now = !now;
		for(int j = 0; j <= 1000; j++) c[!now][j] = 0;
		for(int j = 0; j <= 1000; j++)
			if(c[now][j] != 0) 
			{
				c[!now][j] += c[now][j];
				c[!now][cmmdc(j, a[i + 1])] += c[now][j];
			}
	}

	printf("%d\n", c[!now][1]);
	return 0;
}