
// Lucas.java
// Andrew Davison, ad@coe.psu.ac.th, April 2023

/* Calculate the series of Lucas numbers from
   the 0th up to the nth:
     2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, ....

   https://en.wikipedia.org/wiki/Lucas_number

   Use Nut.lucas() for this, which returns a long.

   Also calculate lucas(99) and lucas(101) and confirm
   that (lucas(99) + lucas(101))/5 = fib(100)

   This requires Nut.lucasBig() which return a BigInteger

   Usage:
     > compile Lucas.java
     > run Lucas <n>
   e.g.
     > run Lucas 30

   Also see Fibonacci.java
*/

import java.math.*;


public class Lucas
{

  public static void main(String[] args)
  {
    if (args.length != 1) {
      System.out.println("Usage: run Lucas <n>");
      return;
    }
    int n = Math.abs(Nut.parseInt(args[0]));

    for(int i=0; i <= n; i++)
      System.out.println(i + ". " + Nut.lucas(i));  

    // test relationship between Lucas and Fibonacci
    System.out.println("\nfib(100) = " + Nut.fibBig(100));
    System.out.println("\n(lucas(99) + lucas(101))/5 = " + 
                Nut.lucasBig(99).add(Nut.lucasBig(101)).
                          divide(BigInteger.valueOf(5)) );
  } /* main */

}  // end of Lucas class
