Cod sursa(job #991032)

Utilizator cont_de_testeCont Teste cont_de_teste Data 29 august 2013 15:31:39
Problema Indep Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream fin("indep.in");
ofstream fout("indep.out");


const int MAX_N = 510;
const int MAX_V = 1010;

int n;
int v[MAX_N];

int dp[MAX_N][MAX_V];


inline int cmmdc(const int &a, const int &b) {
	if (!b) return a;
	return cmmdc(b, a % b);
}


int main() {
	fin >> n;
	for (int i = 1; i <= n; ++i)
		fin >> v[i];
	
	// dp[i][j] = k; max k elements from first i elements, cmmdc = j;
	dp[1][v[1]] = 1;
	for (int i = 2; i <= n; ++i) {
		dp[i][v[i]] = 1;
		for (int j = 1; j < MAX_V; ++j) {
			dp[i][j] += dp[i - 1][j];
		}
		for (int j = 1; j < MAX_V; ++j) {
			int c = cmmdc(j, v[i]);
			dp[i][c] += dp[i - 1][j];
		}
	}
	
	fout << dp[n][1] << '\n';
	
	fin.close();
	fout.close();
}