Cod sursa(job #2641626)

Utilizator popashtefan10Popa Stefan popashtefan10 Data 12 august 2020 10:56:33
Problema Indep Scor 25
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <cstdio>

using namespace std;

const int MAX = 1000;

long long prev_dp[MAX + 5], crt_dp[MAX + 5];

int cmmdc(int a, int b) {
  int r = 0;

  while(b) {
    r = a % b;
    a = b;
    b = r;
  }

  return a;
}

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

  scanf("%d", &n);
  prev_dp[0] = crt_dp[0] = 1;

  for(int i = 1; i <= n; i++) {
    scanf("%d", &x);
    for(int i = 0; i <= MAX; i++) {
      int aux = cmmdc(x, i);
      crt_dp[aux] += prev_dp[i]; /// adaug x la toate subsirurile cu cmmdc-ul i
    }

    for(int i = 0; i <= MAX; i++)
      prev_dp[i] = crt_dp[i];
  }

  printf("%lld", prev_dp[1]);

  return 0;
}