1 条题解

  • 0
    @ 2023-12-14 21:51:52
    #include <stdio.h>
    #include <string.h>
    int main() {
        int a[5000], b[5000], c[5000];
        int n;
        int num = 1;
        scanf("%d", &n);
        if (n < 3) {
            printf("%d\n", n);
            return 0;
        }
        a[1] = 1; b[1] = 2;//初始化数组a,数组b 
        for (int i = 3; i <= n; i++) {
            for (int j = 1; j <= num; j++) {
                c[j] = a[j] + b[j];
            }
            for (int j = 1; j <= num; j++) {
                if (c[j] > 9) { // 进位
                    c[j + 1] += c[j] / 10;
                    c[j] %= 10;
                    if (j + 1 > num) {
                        num++;
                    }
                }
            }
            for (int j = 1; j <= num; j++) {
                a[j] = b[j];
            }
            for (int j = 1; j <= num; j++) {
                b[j] = c[j];
            }
        }
        for (int i = num; i > 0; i--) {
            printf("%d", c[i]);
        }
        return 0;
    }
    
    • 1

    信息

    ID
    218
    时间
    1000ms
    内存
    256MiB
    难度
    5
    标签
    递交数
    224
    已通过
    94
    上传者