public class Factors {
    /* Reads a positive long command-line argument n and
    *  prints the nontrivial divisors of n (all except 1).
    *  Also measures and prints the time elapsed until completion.
    *  Example execution: Factors n
    */
    public static void main(String[] args) {
        long n = Long.parseLong(args[0]);
        Stopwatch watch = new Stopwatch(); // Start measuring time

        System.out.print("Factors: ");
        for (long d = 2; d <= n; d++) {
            // Check if n is evenly divisible by d,
            // print d as a factor and remove this divisor
            while (n % d == 0) {
                System.out.print(d + " ");
                n = n / d;
            }
        }
        System.out.println();
        // Stop measuring and print elapsed time
        System.out.println("Elapsed time: " + watch.elapsedTime() + " sec.");
    }
}
