Cod sursa(job #2381828)

Utilizator PetyAlexandru Peticaru Pety Data 17 martie 2019 13:34:24
Problema Indep Scor 75
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <bits/stdc++.h>

using namespace std;

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

int n, x;
int one[200], dp[1002][200];

void aduna (int a[], int b[]) {
  int t = 0;
  a[0] = max(a[0], b[0]);
  for (int i = 1; i <= max(a[0], b[0]); i++) {
    int aux = a[i] + b[i] + t;
    a[i] = aux % 10;
    t = aux / 10;
  }
  if (t)
    a[++a[0]] = t;
}

int main ()
{
  fin >> n;
  one[0] = one[1] = 1;
  for (int i = 1; i <= n; i++)  {
    fin >> x;
    for (int j = 1; j <= 1000; j++) {
      aduna(dp[__gcd(x, j)], dp[j]);
    }
    aduna(dp[x], one);
  }
  for (int i = dp[1][0]; i >= 1; i--)
    fout << dp[1][i];
  return 0;
}