Cod sursa(job #1040841)

Utilizator AnonymouslegionAnonymous Anonymouslegion Data 24 noiembrie 2013 23:19:37
Problema Indep Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
#include <vector>
#include <cstring>

using namespace std;

long long dp[2][1005];

int cmmdc(int x, int y){
  int z;
  while(y){
    z = x;
    x = y;
    y = z % y;
  }
  return x;
}

int main(){
  ifstream in("indep.in");
  ofstream out("indep.out");

  int n, mix = 0;
  in >> n;
  for(int i = 1; i <= n; ++i){
    for(int j = 1; j <= mix; ++j)
      dp[i & 1][j] = dp[(i + 1) & 1][j];
    int x;
    in >> x;
    mix = max(x, mix);
    for(int j = 1; j <= mix; ++j)
      dp[i & 1][cmmdc(x, j)] += dp[(i + 1) & 1][j];
    ++dp[i & 1][x];
  }

  out << dp[n & 1][1];

  return 0;
}