SolvePell[a_,n_]:=Module[{x=a,y=1,i,tmp},
    For[i=1,i<n,i++,tmp=x;x=a x+(a^2-1)y;y=a y+tmp];
    {x,y}
];

SolvePrime[prime_]:= Module[{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,
                             p,q,r,s,t,u,v,x,y,z,w,pell,index,tmp},
    k=prime-2;
    g=Divide[(k+1)!+1,k+2]-1;
    pell=FindInstance[xx^2-16(k+1)^3 (k+2)yy^2==1&&xx>0&&yy>0,{xx,yy},
                      Integers];
    {n}=yy/.pell;
    n=n-1;
    {f}=xx/.pell;
    p=(n+1)^(k+1);
    q=(p+1)^n;
    z=p^(k+2);
    w=Floor[q/z];
    h=z-(k+1)!(Mod[q,z]);
    j=Mod[q,z]-h;
    e=p+q+z+2n;
    pell=FindInstance[xx^2-e^3 (e+2)yy^2==1&&xx>0&&yy>0,{xx,yy},
                      Integers];
    {a}=yy/.pell;
    a=a-1;
    {o}=xx/.pell;
    For[i=1;x=a;y=1,i<n,i++,tmp=x;x=a x+(a^2-1)y;y=a y+tmp];
    For[i=1;m=a;l=1,i<= k,i++,tmp=m;m=a m+(a^2-1)l;l=a l+tmp];
    i=Divide[l-k-1,a-1];
    v=y-n-l;
    b=Divide[m-p-l(a-n-1),2a(n+1)-(n+1)^2-1];
    s=Divide[x-q-y(a-p-1),2a(p+1)-(p+1)^2-1];
    t=Divide[p m-z-p l(a-p),2a p-p^2-1];
    StringForm["k=``,\ng=``,\nf=``,\nn=``,\np=``,\nq=``,
                   \nz=``,\nw=``,\nh=``,\nj=``,\ne=``,
                   \na=``,\no=``,\nx=``,\ny=``,\nm=``,
                   \nl=``,\ni=``,\nv=``,\nb=``,\ns=``,\nt=``",
                k,g,f,n,p,q,z,w,h,j,e,a,o,x,y,m,l,i,v,b,s,t]
];
