Cod sursa(job #2146121)

Utilizator MiricaMateiMirica Matei MiricaMatei Data 27 februarie 2018 20:01:16
Problema Indep Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <cstdio>
#include <cstring>

using namespace std;

int gcd(int a, int b) {
  while (b) {
    int r = a % b;
    a = b;
    b = r;
  }
  return a;
}

const int MAX_DIGITS = 50;
const int BASE = 1.e6;

class HugeN {
 private:
  int x[MAX_DIGITS];
 public:
  HugeN () {
    memset(x, 0, sizeof(x));
    x[0] = 1;
  }
  void atrib(int nr) {
    x[0] = 0;
    do {
      x[++x[0]] = nr % BASE;
      nr /= BASE;
    } while (nr);
  }
  void print() {
    int aux;
    printf("%d", x[x[0]]);
    for (int i = x[0] - 1; i >= 1; --i) {
      aux = x[i];
      printf("%06d", aux);
    }
    printf("\n");
  }
  HugeN operator+= (const HugeN& other);
};

HugeN HugeN::operator +=(const HugeN& other) {
  x[0] = x[0] > other.x[0] ? x[0] : other.x[0];
  int tr = 0, aux, i;
  for (i = 1; i <= x[0]; ++i) {
    aux = x[i] + other.x[i] + tr;
    x[i] = aux % BASE;
    tr = aux / BASE;
  }
  if(tr)
    x[++x[0]] = tr;
  return *this;
}

HugeN dp[1005];

int main() {
  freopen("indep.in", "r", stdin);
  freopen("indep.out", "w", stdout);

  int n;
  scanf("%d", &n);
  HugeN k;
  k.atrib(1);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    for (int j = 1; j <= 1000; ++j)
      dp[gcd(j, x)] += dp[j];
    dp[x]+=k;
  }

  dp[1].print();

  return 0;
}