linlin6 @ 2022-12-15 12:38:39
#include<iostream>
using namespace std;
long long fibonacci(long long n)
{
if (n == 1)
return 1;
if (n == 2)
return 2;
if (n != 1 && n != 2)
return fibonacci(n - 1) + fibonacci(n - 2);
}
int main()
{
long long N;
cin >> N;
cout << fibonacci(N);
return 0;
}
by 大眼仔Happy @ 2022-12-15 12:39:33
@linlin6 TLE吧。
by FuckYouJinhai @ 2022-12-15 12:40:38
@linlin6 买一本《深基》,然后按照里面说的封装一个高精度类
by 大眼仔Happy @ 2022-12-15 12:46:12
@linlin6 高精度可以写结构体啊。。。
#include<bits/stdc++.h>
using namespace std;
struct data
{
int num[10005];
data(){memset(num,0,sizeof(num));}
data friend operator +(const data A,const data B)
{
data Ans;
//写高精度Ans=A+B
return Ans;
}
void print()
{
//输出高精度
}
};
data a,b,c;
int main(){
c=a+b;
c.print();
return 0;
}
by 2345A @ 2022-12-15 12:56:47
@大眼仔Happy 我用结构体就不行
by 大眼仔Happy @ 2022-12-15 18:17:50
@baiqian ?为什么?
by 2345A @ 2022-12-16 14:20:29
@大眼仔Happy
#include <iostream>
using namespace std;
int daka(int a)
{
if (a <= 1)
{
return 1;
}
else
return daka(a - 1) + daka(a - 2);
}
int main()
{
int b;
cin >> b;
cout << daka(b);
return 0;
}
by 大眼仔Happy @ 2022-12-16 18:19:59
@baiqian 你这叫结构体?
by Etic_HAO @ 2022-12-20 16:59:58
@baiqian
这样会T掉吧
by bitset_iTM @ 2022-12-20 19:32:02
@linlin6 你甚至还要写个记忆化,建议用高精+数组模拟。
by mediocre_ @ 2022-12-23 16:58:00
《结构体》