#include <stdio.h>
#include <math.h>

int main(void){
  int x,y,z;
  int xxx,yyy,zzz;
  int sq,mxy;
  int max;

  double d3 = 1.0/3.0;

  while( 1 ){
    scanf("%d ",&z );
    if( !z )
      break;

    zzz = z*z*z;
    sq = z/pow( 2.0,1.0/3.0 );
    x = sq;

    max = 0;
    for( x=1;x<=sq;x++ ){
      xxx = x*x*x;
      y = pow( zzz-xxx, d3 );
      yyy=y*y*y;
      mxy = xxx+yyy;
      if( max<mxy )
	max=mxy;
    }
    printf("%d\n",zzz-max);
  }
  return 0;
}