求任意数列通项

笔记

求任意数列通项

#include<bits/stdc++.h>
using namespace std;
long long f[]={0, 1, 1, 2, 8, 18, 59, 155, 460, 1276, 3672, 10357, 29533};
int main()
{
    int len=sizeof(f)/sizeof(f[0]);
    int a,b,c,d,e,k;
    int  n=5;
    int start=-10,end=10;
    for(a=start;a<=end;a++){
        for(b=start;b<=end;b++){
            for(c=start;c<=end;c++){
                for(d=start;d<=end;d++){
                    for(e=start;e<=end;e++){
                        for(k=start;k<=end;k++){
                            if(f[n]==(a*f[n-1]+b*f[n-2]+c*f[n-3]+d*f[n-4]+e*f[n-5]+k)){
                                int flag=0;
                                for(int m=n;m<len;m++){
                                    if(!(f[m]==(a*f[m-1]+b*f[m-2]+c*f[m-3]+d*f[m-4]+e*f[m-5]+k))){
                                        flag=1;
                                        break;
                                    }
                                }
                                    if(flag==0){
                                        cout<<"ok!"<<endl;
                                        cout<<"a= "<<a<<" b= "<<b<<" c= "<<c<<" d= "<<d<<" e= "<<e<<" k= "<<k<<endl;
                                        cout<<"General formula:"<<endl;
                                        printf("f[n] = %d*f[n-1] + %d*f[n-2] + %d*f[n-3] + %d*f[n-4] + %d*f[n-5] + %d\n\n",a,b,c,d,e,k);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    return 0;
}
c4c

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注