Cod sursa(job #2931651)

Utilizator RolandPetreanPetrean Roland RolandPetrean Data 31 octombrie 2022 18:04:17
Problema Indep Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
// https://infoarena.ro/problema/indep
#include <bits/stdc++.h>
using namespace std;

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

const int N=500, VMAX=1000, NC=200;
int n, dp[2][VMAX][NC], unu[NC]={1,1};

void copie(int dest[NC], int sursa[NC]) {
  for (int i=0; i<NC; ++i) dest[i] = sursa[i];
}

void suma(int s[NC], int a[NC], int b[NC]) {
  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;
}

void afis(int nr[NC]) {
  for (int i=nr[0]; i>0; --i) cout<<nr[i];
  cout<<endl;
}

int test[NC], t1[NC]={1, 5}, t2[NC]={3, 3,2,1};

int main() {
  int n;
  fin>>n;

  for (int i=1; i<=n; ++i) {
    int v_i;
    fin>>v_i;
    if (i==1) {
      dp[1][v_i][0] = dp[1][v_i][1] = 1;
      continue;
    }

    int i_c=i%2, i_a=1-i_c;
    for (int j=1; j<=VMAX; ++j) copie(dp[i_c][j], dp[i_a][j]);
    for (int j=1; j<=VMAX; ++j) {
      int d=__gcd(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);
  }

  n %= 2;
  for (int i=dp[n][1][0]; i>0; --i) fout<<dp[n][1][i];
}