P2673 《瞿葩的数字游戏》T1-数字王国的门神

· · 个人记录

题目传送门

\mathcal{Description}

表示斐波那契数列的第 i 项,给定 m,n 求 \lim\limits_{k \to \infty } \left( \sum\limits_{i=1}^kf_i\times10^{k-i} \right) 的第 m 到第 n 位。

\mathcal{Solution}

推式子,在这个数前面加上 0.,转为小数,即。

\sum_{i=1} ^ {\infty} \frac{1}{\sqrt5} \left[ \left( \frac{1+\sqrt{5}}{20} \right)^i- \left(\frac{1-\sqrt{5}}{20} \right)^i \right]

最后是 \dfrac{10}{89} 。

时间复杂度 O(n) ,空间复杂度 O(1) 。

\mathcal{Code}

//
// Created by liliz on 2022/12/20.
//

#include <bits/stdc++.h>

using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);

    int l, r, x = 10;
    cin >> l >> r;
    for (int i = 1; i <= r; i++) {
        if (i >= l) cout << x * 10 / 89;
        x = x * 10 % 89;
    }

    return 0;
}