import java.lang.* ; import java.util.* ; import java.math.* ; /** * @brief Sequence A306403 of the Online Encyclopedia of Integer Sequences. * @since 2019-02-13 * @author R. J. Mathar */ class A306403 { int n ; /** Ctor * @param n The number to be partitioned into 3 positive parts. */ A306403(int n) { this.n = n ; } /*!******************************************* * @brief compute the associated number of distinct products. * The parameter n is decomposed in all possible ways into * 3 positive partitions; all products of the 3 parts are gathered * in a set, and eventually the size of this set is returned. * @return the number of different products */ int diffprod() { /* prods accumulates the different products of the 3-partitions of n */ Vector prods = new Vector() ; /* loop over all ordered 3-partitions, part[0]<=part[1]<=part[2]. */ int[] parts = new int[3] ; /* part[0]+2*pars <= n */ for(parts[0] =1 ; 3*parts[0] <= n ; parts[0]++) { for(parts[1] = parts[0] ; parts[0]+2*parts[1] <= n ; parts[1]++) { parts[2] = n-parts[0]-parts[1] ; /* Compute the product. Use unlimited integers to avoid overflow of 32 bits */ BigInteger prod = BigInteger.valueOf(parts[0]) ; prod = prod.multiply(BigInteger.valueOf(parts[1])) ; prod = prod.multiply(BigInteger.valueOf(parts[2])) ; /* Is it new? if yes add to the vector of known products */ int kno = prods.indexOf(prod) ; if ( kno < 0 ) { prods.add(prod) ; kno = prods.size()-1 ; } } } return prods.size(); } /*!***************************** * @brief produce a list of values of A306403 in b-file format. */ public static void main(String[] args) { /* loop over all n>=0 until interrupted. */ for(int n=0 ; ; n++) { A306403 a277 = new A306403(n) ; int a = a277.diffprod() ; /* print n and a(n) in a single line */ System.out.println(""+n + " " + a) ; } } } /* A306403 */