#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

signed main(){
    int n;
    vector<int> d;
    rep(i, 1, 1111) rep(j, 1, 1111){
        d. push_back(i*i*i + j*j*j);
    }
    sort(all(d));
    while(cin >> n, n){
        int z3 = n*n*n;
        int ind = upper_bound(all(d), z3) - 1 - d.begin();
        cout << z3 - d[ind] << endl;
    }
}