跳到正文

个人记录

P1255

czc2012约 2 分钟
原文
文章信息与版本

文章信息

收录
2026年2月11日
更新
2026年2月11日
篇幅
约 2 分钟

版本

  1. v1当前

题目:P1255

思路1

预处理FibFib数列,相加即可。

Res:

  • int:40int:40
  • longlong long:50long:50
  • unsignedunsigned longlong long:50long:50

看来还得用高精啊

思路2

仍预处理FibFib,CC数组存放当前11~ii的FibFib之和。

C++
#include<bits/stdc++.h>
using namespace std;
const int N=5000+5;
int n,jw=1,a[N],b[N],c[N];
void f(){
    a[1]=1,b[1]=2;
    for(int i=3;i<=n;i++){
        for(int j=1;j<=jw;j++) c[j]=a[j]+b[j];
        for(int j=1;j<=jw;j++){
            if(c[j]>9){
                c[j+1]+=c[j]/10;
                c[j]%=10;
                if(j+1>jw) ns++;
            }
        }
        for(int j=1;j<=jw;j++) a[j]=b[j];
        for(int j=1;j<=jw;j++) b[j]=c[j];
    }
}
int main(){
    cin>>n;
    if(n<3){cout<<n;return 0;}
    f();
    for(int i=jw;i>0;i--) cout<<b[i];
    return 0;
}

ACAC

原文