5
1 8 1 7 9
 4
6 7 4 5
 5
36 37 6 18 36
 3
5 1 3
 200
2 1 1 1 2 1 2 1 1 1 2 1 2 2 2 1 1 2 1 2 1 1 1 2 2 1 2 1 1 2 1 1 1 2 1 1 2 2 2 2 2 2 2 2 2 2 1 2 2 1 2 1 2 2 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 2 1 1 2 1 2 2 2 1 2 1 1 1 2 1 1 2 2 1 2 2 1 2 2 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 2 2 1 2 1 1 1 2 2 1 2 2 2 1 1 2 1 2 2 1 2 2 2 1 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 1 2 2 2 1 2 1 1 1 1 2 1 2 1 2 1 1 1 2 2 2 1 2 1 1 2 2 1 1 1 1 1 2 2 2 1 2 2
 10
104105246720 52052623360 213207545282560 426415090565120 6354080 832841973760 26650943160320 6506577920 50832640 832841973760
 3
9 4 4
 10
3 3 3 3 3 3 3 3 3 3
 100
24 33 88 55 4 24 19 19 63 90 9 47 24 74 21 43 20 100 58 15 36 66 13 4 9 51 24 96 50 27 100 41 92 9 67 94 17 11 98 24 72 57 96 85 50 9 45 41 63 76 80 59 25 67 21 84 88 15 62 60 79 65 5 66 1 85 92 100 61 75 44 96 53 97 2 28 83 42 60 42 34 73 44 99 58 46 75 100 75 55 35 52 93 80 69 75 50 67 100 77
 200
1 2 1 2 2 1 2 2 2 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 1 2 2 1 2 2 1 2 1 2 1 2 1 2 2 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 2 1 2 1 1 1 1 1 1 1 2 1 2 2 2 2 2 2 1 1 1 2 2 2 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 1 2 2 1 1 2 1 2 1 2 1 1 1 2 2 2 1 1 1 2 2 2 1 2 1 2 2 1 2 2 2 1 1 1 1 1 2 2 2 2 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() {
  const int _106 = 1000001;
  bool data[_106 + 100];
  int prime[80000], cost[80000];
  int a, b, k;
  while (~scanf("%d%d%d", &a, &b, &k)) {
    int _begin = 0, _end = 0, ii = 1;
    while (_begin == 0) {
      if (prime[ii] >= a) _begin = ii;
      ii++;
    }
    while (_end == 0) {
      if (prime[ii] >= b) _end = ii;
      ii++;
    }
    int _beginc = 0, _endc = 0, kkkk;
    kkkk = k;
    if (prime[_end] > b) {
      _end--;
    }
    _endc = b - prime[_end];
    while (kkkk--) {
      _endc = _endc + cost[_end - kkkk + 1];
    }
    kkkk = k;
    if (a < prime[_begin]) {
      _beginc = prime[_begin] - a;
    }
    while (kkkk--) {
      _beginc = _beginc + cost[_begin + kkkk];
    }
    if (_end - _begin + 1 < k) {
      printf("-1\n");
      break;
    }
    int maxc = max(_beginc, _endc);
    int s = 0;
    for (int i = _begin + 1; i <= _begin + k; i++) {
      s = s + k;
      maxc = max(maxc, s);
    }
    for (int i = _begin + k + 1; i <= _end; i++) {
      s = s + cost[i] - cost[i - k];
      maxc = max(maxc, s);
    }
    printf("%d\n", maxc);
  }
  return 0;
}
int mian() {
  int mapp[100][100], a[1000], ansk, ans[1000][4], n, hang[100];
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &hang[i]);
  }
  int k = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= hang[i]; j++) {
      scanf("%d", &mapp[i][j]);
      a[k++] = mapp[i][j];
    }
  }
  sort(a, a + k);
  ansk = 0;
  k = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= hang[i]; j++) {
      int t = a[k++];
      if (mapp[i][j] == t) continue;
      for (int i1 = i; i1 <= n; i1++) {
        for (int j1 = 1; j1 <= hang[i1]; j1++) {
          if (mapp[i1][j1] == t) {
            ans[ansk][0] = i;
            ans[ansk][1] = j;
            ans[ansk][2] = i1;
            ans[ansk][3] = j1;
            ansk++;
            swap(mapp[i][j], mapp[i1][j1]);
          }
        }
      }
    }
  }
  cout << ansk << endl;
  for (int i = 0; i < ansk; i++) {
    cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " "
         << ans[i][3] << endl;
  }
  return 0;
}
int main() {
  while (cin >> n) {
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i <= n; ++i) {
      dp[i] = 10000000000000;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      while (a[i] > 0 && a[i] % 2 == 0) a[i] /= 2, cnt[i]++;
    }
    a[n] = 1;
    cnt[n] = 0;
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
      dp[i] = i;
      for (int j = 0; j < i; j++) {
        if (a[j] % a[i] == 0 &&
            (cnt[i] == 0 || (i - j) == (cnt[i] - cnt[j]) || (i - j) > cnt[i]))
          dp[i] = min(dp[i], dp[j] + i - j - 1);
      }
    }
    cout << dp[n] << endl;
  }
}
