/* bc program tangent */ /* This constructs the tangent number t[n]. In fact it constructs t[1],...,t[n]. See slides by Richard Brent at https://maths-people.anu.edu.au/~brent/pd/tangent.pdf */ define tangent(n){ auto k,j t[1]=1 for(k=2;k<=n;k++){ t[k]=(k-1)*t[k-1] } for(k=2;k<=n;k++){ for(j=k;j<=n;j++){ t[j]=(j-k)*t[j-1]+(j-k+2)*t[j] } } /* for(k=1;k<=n;k++){ print "t[",k,"]=",t[k]," " }*/ return(t[n]) } define tangentp(n,p){ auto k,j,temp1,temp2 t[1]=1 for(k=2;k<=n;k++){ t[k]=((k-1)*t[k-1])%p } for(k=2;k<=n;k++){ for(j=k;j<=n;j++){ temp1=((j-k)*t[j-1])%p temp2=((j-k+2)*t[j])%p t[j]=(temp1+temp2)%p } } for(k=1;k