
// Tau.java
// Andrew Davison, ad@coe.psu.ac.th, April 2023

/* Print the first MAX_NUM Tau numbers starting from 1.

   A Tau number is a positive integer divisible by the 
   count of its positive divisors. 
   https://en.wikipedia.org/wiki/Refactorable_number
and
   https://rosettacode.miraheze.org/wiki/Tau_number

   This code uses Nut.getDivisors() to return a list of
   Integers. For BigInteger factors, use JML's Divisors
   class, as shown at the end of main().

   Usage:
     > compile Tau.java
     > run Tau
*/

import java.util.*;
import java.math.*;

import de.tilman_neumann.jml.Divisors;

import org.apache.log4j.*;


public class Tau
{
  private static final int MAX_NUM = 100;

  public static void main(String[] args)
  {
    BasicConfigurator.configure();
    Logger.getRootLogger().setLevel(Level.OFF);
      // to stop a "No appenders could be found for logger" warning when using Divisors

    System.out.println("The first " + MAX_NUM + " Tau numbers are: ");
    int count = 0;
    int n = 1;
    while (count < MAX_NUM) {
      if (n % Nut.getDivisors(n).size() == 0) {
        System.out.printf("%4d ", n);
        count++;
        if (count % 10 == 0)
          System.out.println();
      }
      n++;
    }

    // using JML's Divisors class
    BigInteger big = new BigInteger("105327569");
    SortedSet<BigInteger> divs = Divisors.getDivisors(big);
    List<BigInteger> divsList = new ArrayList<>(divs);
    System.out.println("\nDivisors of " + big + " = " + divsList);
                                       // or just print divs
  } /* main */


}  // end of Tau class