christmas/Christmas.java

  1 /*
  2   Southeast USA -- division 2, 2013.  Problem B: The n Days of Christmas
  3   Categories: math
  4  */
  5 import java.io.*;
  6 import java.util.Scanner;
  7 import java.util.*;
  8 
  9 public final class Christmas {
 10 
 11    private static final Scanner STDIN =
 12       new Scanner (new BufferedInputStream (System.in));
 13 
 14    private static final PrintStream STDOUT =
 15       new PrintStream (new BufferedOutputStream (System.out));
 16 
 17 
 18    public static void main (final String[] args) {
 19 
 20       input: for (int ds=1; /**/; ds++) {
 21          final long n = STDIN.nextLong();
 22          if (n==0) break;
 23          assert 0<n && n<=1_000_000L;
 24          final long x = n * (n+1L) / 2L;
 25          assert 0<x && x<=1_000_001_000_000L / 2L;
 26          final long y = x * (n+2L) / 3L;
 27          assert 0<y && y<=1_000_002_000_002_000_000L / 3L;
 28          STDOUT.println (y);
 29       }
 30       STDOUT.close();
 31    }
 32 }
 33 
 34 /*
 35  * ------------For GNU Emacs ------------
 36  * Local Variables:
 37  * compile-command:  javac Christmas.java 
 38  * End:
 39  */