import std.string; import std.math; double fabs( cdouble z ){ return sqrt( z.re*z.re + z.im*z.im ); } cdouble conj( cdouble z ){ return (z.re - 1i*z.im); } cdouble pow( cdouble z1, cdouble z2 ){ double r1, f1; double lr1; double mod, phase; r1 = fabs(z1); f1 = atan2( z1.im, z1.re ); lr1 = log( r1 ); mod = exp( lr1*z2.re - f1*z2.im ); phase = ( lr1*z2.im + f1*z2.re ); return mod*cos(phase) + 1i*mod*sin(phase); } cdouble pow( cdouble x, uint n ){ cdouble p; switch( n ){ case 0: p = 1.0; break; case 1: p = x; break; case 2: p = x * x; break; default: p = 1.0; while( 1 ){ if( n&1 ) p *= x; n >>= 1; if( !n ) break; x *= x; } break; } return p; } /** Computes the following: n! Cr(n,k) = ----------- k! (n-k)! */ ulong nChoosek( char n, char k ){ ulong tmp = 1; ulong ii, jj; int a, b; if( n>=34 ) throw new Error("nChoosek("~std.string.toString(n)~ ","~std.string.toString(k)~") - inacurate result!"); if( n>30 ) return ( nChoosek(n-1,k-1) + nChoosek(n-1,k) ) ; if( (k==0) || (k==n) || ( (n==0) && (k==0) ) ) return 1; if( (n-k)>k ){ a = (n-k); b = k; } else { a = k; b = (n-k); } // I think that the following code could be implemented in a faster way jj = 1; for( ii=a+1; ii<=n; ii++ ){ tmp *= ii; if( jj<=b ){ tmp /= jj; jj++; } } for( ii=jj; ii<=b; ii++ ) tmp /= ii; return tmp; } int main( ){ printf("%.*s\n",toString(pow(1i,1i))); return 0; }