Stores logX to the base K
int k = ( int ) ( Math . Log ( x ) / Math . Log ( base1 ) ) ; if ( Math . Abs ( Math . Pow ( base1 , k ) - x ) < Math . Abs ( Math . Pow ( base1 , ( k + 1 ) ) - x ) ) return ( int ) Math . Pow ( base1 , k ) ; else return ( int ) Math . Pow ( base1 , ( k + 1 ) ) ; }