わかりました、ここに詳細があります: 私は Java で Nth Hardy's Taxi 番号(2 つの立方数の 2 つの異なるセットで合計できる数) を見つけるクラスを作成しています。ディスカバリー自体はダウンしていますが、スペースを節約する必要があります。そのためには、contains() のようなメソッドを比較的簡単に使用または作成できる、可能な限り最小のデータ構造が必要です。私の現在のソリューションは確かに時間制限内でうまく計算できるので、速度については特に心配していません。
つまり、データ構造には次のものが必要です。
- contains() メソッドを比較的簡単に実装できるようにするため
 - 少量のメモリを使用するには
 - 非常に多くのエントリを保存できるようにするため
 - プリミティブな long 型で使いやすいように
 
何か案は?ハッシュ マップから始めて (正確さを確保するために、合計につながる値をテストする必要があったため)、信頼できる答えが保証されたら、ハッシュ セットに移動しました。
スペースを節約する方法に関する他の一般的なアイデアは大歓迎です!
質問に答えるのにコードは必要ないと思いますが、興味がある場合はここにあります。
public class Hardy {
//  private static HashMap<Long, Long> hm;
/**
 * Find the nth Hardy number (start counting with 1, not 0) and the numbers
 *      whose cubes demonstrate that it is a Hardy number.
 * @param n
 * @return the nth Hardy number
 */
public static long nthHardyNumber(int n) {
//      long i, j, oldValue;
    int i, j;
    int counter = 0;
    long xyLimit = 2147483647; // xyLimit is the max value of a 32bit signed number
    long sum;
//      hm = new HashMap<Long, Long>();
    int hardyCalculations = (int) (n * 1.1);
    HashSet<Long> hs = new HashSet<Long>(hardyCalculations * hardyCalculations, (float) 0.95);
    long[] sums = new long[hardyCalculations];
//      long binaryStorage, mask = 0x00000000FFFFFFFF;
        for (i = 1; i < xyLimit; i++){
            for (j = 1; j <= i; j++){
//                  binaryStorage = ((i << 32) + j);
//                  long y = ((binaryStorage << 32) >> 32) & mask;
//                  long x = (binaryStorage >> 32) & mask;
                sum = cube(i) + cube(j);
                if (hs.contains(sum) && !arrayContains(sums, sum)){
//                      oldValue = hm.get(sum);
//                      long oldY = ((oldValue << 32) >> 32) & mask;
//                      long oldX = (oldValue >> 32) & mask;
//                      if (oldX != x && oldX != y){
                    sums[counter] = sum;
                    counter++;
                    if (counter == hardyCalculations){
//                          Arrays.sort(sums);
                        bubbleSort(sums);
                        return sums[n - 1];
                    }
                } else {
                    hs.add(sum);
                }
            }
        }
        return 0;
}
private static void bubbleSort(long[] array){
    long current, next;
    int i;
    boolean ordered = false;
    while (!ordered) {
        ordered = true;
        for (i = 0; i < array.length - 1; i++){
            current = array[i];
            next = array[i + 1];
            if (current > next) {
                ordered = false;
                array[i] = next;
                array[i+1] = current;
            }
        }
    }
}
private static boolean arrayContains(long[] array, long n){
    for (long l : array){
        if (l == n){
            return true;
        }
    }
    return false;
}
private static long cube(long n){
    return n*n*n;
}
}