Cod sursa(job #2665719)

Utilizator hurjui12AlexandruHurjui Alexandru-Mihai hurjui12Alexandru Data 31 octombrie 2020 11:37:26
Problema Indep Scor 25
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
using namespace std;

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

inline int gcd(int x, int y)
{
	int r;
	while (y)
	{
		r = x%y;
		x = y;
		y = r;
	}
	return x;
}

long long dp[2][1001];
//dp[i] = numarul de subsiruri cu gcd-ul i

int main()
{
	int n, x, i, j;
	dp[0][0] = 1;
	fin >> n;
	for (i = 1; i<=n; i++)
	{
		fin >> x;
		for (j = 0; j<=1000; j++)
			dp[i&1][j] = dp[(i&1)^1][j];
		for (j = 0; j<=1000; j++)
			dp[i&1][gcd(x, j)] += dp[(i&1)^1][j];
		/*
		for (j = 0; j<=6; j++)
			fout << dp[i&1][j] << ' ';
		fout << '\n';
		 */
	}
	fout << dp[n&1][1];
	return 0;
}