import java.util.*; public class SommaDiDueCubiHash { // Classe per tener coppie (a, b) static class Pair { int a, b; Pair(int a, int b) { this.a = a; this.b = b; } @Override public String toString() { return a + "^3 + " + b + "^3"; } } public static void main(String[] args) { if (args.length != 1) { System.out.println("Uso: java RamanujanOptimized "); return; } int n; try { n = Integer.parseInt(args[0]); } catch (NumberFormatException e) { System.out.println("Errore: inserire un intero valido."); return; } // Mappa: somma (long) -> lista di coppie (a, b) Map> map = new HashMap<>(); for (int a = 1; a <= n; a++) { for (int b = a + 1; b <= n; b++) { long sum = (long)a * a * a + (long)b * b * b; if (sum > n) continue; // Aggiungi la coppia alla mappa if (!map.containsKey(sum)) { map.put(sum, new ArrayList<>()); } map.get(sum).add(new Pair(a, b)); } } // Scorri le somme che hanno almeno due coppie for (Map.Entry> entry : map.entrySet()) { List list = entry.getValue(); if (list.size() >= 2) { long sum = entry.getKey(); // Per ogni coppia almeno due diverse // Stampiamo tutti i modi distinti (evitando inversioni) // Per esempio, solo combinazioni (i, j) con i