pi<=1000很小啊
#include
int main()
{
int a[1005],i,n;
a[1]=a[2]=1;
for(i=3;i<1001;i++)a[i]=a[i-1]+a[i-2];
scanf("%d",&n);
while(n--)
{
scanf("%d",&i);
printf("%d\n",a[i]);
}
return 0;
}
#include
#include
#define N 100
using namespace std;
struct bignum{
unsigned int a[N];
bignum(unsigned long long n=0){
for(int i=0;ia[i]=n%1000000000;
n/=1000000000;
}
}
bignum operator+(const bignum n)const;
bool operator==(const int n)const;
bool operator!=(const int n)const;
}fib[1001];
bignum bignum::operator+(const bignum n)const{
bignum temp=*this;
for(int i=0;itemp.a[i]+=n.a[i];
temp.a[i+1]+=temp.a[i]/1000000000;
temp.a[i]%=1000000000;
}
temp.a[N-1]+=n.a[N-1];
return temp;
}
bool bignum::operator==(const int n)const{
bool flag=true;
for(int i=1;iif(a[i])
flag=false;
return (a[0]==n)&flag;
}
bool bignum::operator!=(const int n)const{
return !((*this)==n);
}
ostream &operator<<(ostream &out,const bignum &n){
int i=N-1;
while(!n.a[i]){
--i;
if(i<0){
out<<0;
return out;
}
}
out<for(;i>=0;i--)
out<return out;
}
bignum fibonacci(int n){
if(fib[n]!=0)
return fib[n];
if(n==0)
return fib[n]=0;
if(n==1)
return fib[n]=1;
return fib[n]=fibonacci(n-1)+fibonacci(n-2);
}
int main(){
int n;
while(cin>>n){
cout<}
return 0;
}
自己写一个高精度进行了