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

int main(void){
  int x,y,z;
  int zzz;
  int sq,ans;
  int xxx,yyy;
  int dx;

  while( 1 ){
    scanf("%d ",&z );
    if( !z )
      break;
    zzz = z*z*z;
    sq = z/pow( 2.0,1.0/3.0 );
    x = sq;
    y = sq;
    xxx = x*x*x;
    yyy = xxx;
    ans = zzz - ( xxx+yyy );

    while( 1 ){
      dx = 3*x*x+3*x+1;
      if( ans>dx ){
	ans-=dx;
	x++;
      }else
	break;
    }
    /*
    printf("x=%d ,y=%d, z=%d\tz^3=%d x^3=%d,y^3=%d \n",
	   x,y,z,z*z*z,x*x*x,y*y*y);
    */
    printf("%d\n",ans);
  }
  return 0;
}