class Complex { public double r,i; Complex(){ } Complex(double r,double i){ this.r = r; this.i = i; } static Complex pow( Complex Z, double n) { double q,r,t; q = Z.r*Z.r + Z.i*Z.i; if ( q == 0 ){ return new Complex( 0.0 , 0.0 ); }else{ r = Math.sqrt( q ); } if( r == 0 ){ return new Complex( 0.0 , 0.0 ); }else if( Z.i > 0 ){ t = Math.acos( Z.r / r ); }else{ t = 2*Math.PI - Math.acos( Z.r / r ); } return new Complex(Math.pow( r,n ) * Math.cos( n * t ),Math.pow( r,n ) * Math.sin( n * t )); } static Complex sqrt( Complex Z) { double q,r,t; q = Z.r*Z.r + Z.i*Z.i; if ( q == 0 ){ return new Complex( 0.0 , 0.0 ); }else{ r = Math.sqrt( q ); } if( r == 0 ){ return new Complex( 0.0 , 0.0 ); }else if( Z.i > 0 ){ t = Math.acos( Z.r / r ); }else{ t = 2 * Math.PI - Math.acos( Z.r / r ); } return new Complex(Math.sqrt( r ) * Math.cos( t / 2 ),Math.sqrt( r ) * Math.sin( t / 2)); } }