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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open("in.in","r",stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++){
		dp[i] = i - 1;
		if(a[i] % 2 == 1){
			// find j < i so that a[i] is a factor of a[j]
			for(int j = 1; j < i; j++){
				if(a[j] % a[i] == 0){
					dp[i] = min(dp[i], dp[j] + (i - j - 1));
				}
			}
		} else{
			int p = a[i], q = a[i] / 2;
			bool canFind = false;
			int ID = 0;
			for(int j = i - 1; j >= 1; j--){
				if(a[j] % p == q){
					dp[i] = min(dp[i], dp[j] + (i - j - 1));
					canFind = true;
					break;
				}
				ID = j;
				if(q % 2 == 1) break;
				p /= 2, q /= 2;
			}
			if(!canFind){
				for(int j = ID - 1; j >= 1; j--){
					if(a[j] % q == 0){
						dp[i] = min(dp[i], dp[j] + (i - j - 1));
					}
				}
			}
		}
	}
	int ans = 1e9 + 1;
	for(int i = 1; i <= n; i++){
		ans = min(ans, dp[i] + (n - i));
	}
	cout << ans << "\n";
}