题解 【P8808 [蓝桥杯 2022 国 C] 斐波那契数组】
题解
记
记修改完后的序列为
容易根据数学归纳法得到,
假如
不过,这个式子成立的前提是
当然,最终
时间复杂度
参考代码
#include<bits/stdc++.h>
#define up(l, r, i) for(int i = l, END##i = r;i <= END##i;++ i)
#define dn(r, l, i) for(int i = r, END##i = l;i >= END##i;-- i)
using namespace std;
typedef long long i64;
const int INF = 2147483647;
int qread(){
int w=1,c,ret;
while((c = getchar()) > '9' || c < '0') w = (c == '-' ? -1 : 1); ret = c - '0';
while((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + c - '0';
return ret * w;
}
const int MAXN = 1e6 + 3;
int H[MAXN], u = 1, v = 1, t, m = 1e6;
int main(){
int n = qread();
up(1, n, i){
int a = qread(); if(a % u == 0) H[a / u] ++;
if(u < m) t = v, v = u + v, u = t;
}
int ans = INF;
up(1, m, i) ans = min(ans, n - H[i]);
printf("%d\n", ans);
return 0;
}