/* looks for pairs of natural numbers x, y such that x^2 + y^2 = z^2 with z natural All pairs x < y <= mxn are tested */ import java.util.Hashtable; public class Equazioni { static Hashtable ratioes = new Hashtable(); public static String toString(long a, long b) { return a+","+b; } public static long MCD(long a, long b) { // a e b qualsiasi a = Math.abs(a); b = Math.abs(b); if(a>=b) return calcolaMCDEuclide(a, b); else return calcolaMCDEuclide(b, a); } public static long calcolaMCDEuclide(long a, long b) { // assumo a >= b while(b!=0) { long resto = a%b; a = b; b = resto; } return a; } public static boolean add(long a, long b) { long ar, br; long mcd = MCD(a,b); ar = a/mcd; br = b/mcd; String s = toString(ar, br); if(ratioes.get(s) == null) { ratioes.put(s, s); return true; } return false; } public static void main(String[] args) { if(args.length != 1) { System.out.println("Usage: java Equazioni maxn\n where maxn is the maximum value to be tested for\n"); System.exit(0); } long max = Integer.parseInt(args[0]); long n = 0; System.out.printf(" n | cateto1 | cateto2 | ipotenusa\n----------+-----------+-----------+-------------\n"); for(long x=1; x