Pagini recente » Cod sursa (job #1120554) | Cod sursa (job #791233) | Cod sursa (job #860884) | Cod sursa (job #1980994) | Cod sursa (job #2931659)
#include <fstream>
using namespace std;
const int N = 500;
const int VMAX = 1000;
const int NC = 200;
short int n, dp[2][1+VMAX][NC], unu[NC] = {1, 1};///unu = (1, 1, 0, 0, 0, ....)
ifstream in("indep.in");
ofstream out("indep.out");
void copie(short int dest[NC], short int sursa[NC])
{
for (short int i = 0; i < NC; i++)
{
dest[i] = sursa[i];
}
}
void suma(short int s[NC], short int a[NC], short int b[NC])
{
short int t = 0, i = 1;
while (i <= a[0] || i <= b[0] || t > 0)
{
int aux = a[i] + b[i] + t;
s[i] = aux % 10;
t = aux / 10;
i++;
}
s[0] = i - 1;
}
int cmmdc(short int a, short int b)
{
while (b != 0)
{
int r = a % b;
a = b;
b = r;
}
return a;
}
void afis(short int v[NC])
{
for (short int i = v[0]; i >= 1; i--)
{
out << v[i];
}
}
int main()
{
in >> n;
for (short int i = 1; i <= n; i++)
{
short int v_i;
in >> v_i;
if (i == 1)
{
copie(dp[1][v_i], unu);
continue;
}
short int i_c = i % 2;
short int i_a = 1 - i_c;
for (short int j = 1; j <= VMAX; j++)
{
copie(dp[i_c][j], dp[i_a][j]);
}
for (short int j = 1; j <= VMAX; j++)
{
short int d = cmmdc(v_i, j);
suma(dp[i_c][d], dp[i_c][d], dp[i_a][j]);
}
suma(dp[i_c][v_i], dp[i_c][v_i], unu);
}
///afisam dp[n % 2][1]
afis(dp[n%2][1]);
in.close();
out.close();
return 0;
}