Cod sursa(job #67462)

Utilizator peanutzAndrei Homorodean peanutz Data 24 iunie 2007 23:09:10
Problema Indep Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <stdio.h>
#include <string.h>
#define NMAX 1000

long long a[2][NMAX+5];
int n;

int cmmdc(int a, int b)
{
	while(a != b)
	{
        if(a > b)
			a -= b;
		else
			b -= a;
     }
	return a;
}

int main()
{
	int stare = 0, i, j, x, aux;
	freopen("indep.in", "r", stdin);
	freopen("indep.out", "w", stdout);

	scanf("%d", &n);

	scanf("%d", &x);


	for(j = 1; j <= x; ++j)
		if(!(j%x))
			a[stare][j] = 1;
	a[stare][x] = 1;

	for(i = 2; i <= n; ++i)
	{
		//for(int k = 1; k <= NMAX; ++k) printf("%d ", a[stare][k]); printf("\n");

		scanf("%d", &x);
		stare = 1-stare;

		memset(a[stare], 0, sizeof(a[stare]));


		for(j = 1; j <= x; ++j)
		{
			aux = cmmdc(x,j);
			a[stare][ aux ] += a[1-stare][j] + a[1-stare][ aux ];
		}
		++a[stare][x];
	}

	printf("%lld", a[stare][1]);

	return 0;
}