//Apery.java //probability that 3 integers have no factors in common (i.e. they are relatively prime) is 1/Apery // Apery's constant 1.2020569031... sum of i^-3 (1+1/2^3+1/3^3+1/4^3...) // sum of the inverses of the cubes of the positive integers is irrational. //reciprocal is .83190737... //incomplete... import java.awt.*; import javax.swing.*; public class Apery { public static final int MAXBINS=30; public static void main (String[] args) { int maxInt, trials, a, b, c; int triplesThatHaveCommonFactors = 0; String input; input = JOptionPane.showInputDialog("Max range of integers","1000000000"); maxInt = Integer.parseInt(input); input = JOptionPane.showInputDialog("Number of trials","1000000"); trials = Integer.parseInt(input); /*System.out.println(""+euclid(156,330)); System.out.println(""+euclid(330,156)); System.out.println(""+euclid(56,153)); System.out.println(""+euclid(63,72)); */ for (int i=0; i 1) //a and b not relatively prime if (euclid(a,c) > 1) //a and c not relatively prime if (euclid(b,c) > 1) //b and c not relatively prime triplesThatHaveCommonFactors++; } System.out.println(""+(1-(double)triplesThatHaveCommonFactors/trials)); } public static int euclid(int a, int b) { int r; if (b > a) { int x=b; b=a; a=x; } //swap so a>b while (b > 0){ r = a % b; a = b; b = r; } return a; } }