/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
 * Name: COS 126 Staff                                                       *
 * Login: cos126                                                             *
 * Precept: P00                                                              *
 *                                                                           *
 * Description: Prints info about aliquot cycles of numbers on StdIn.        *
 *                                                                           *
 * Dependencies: StdIn.java, StdOut.java, Perfect.java, Cuddly.java          *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

public class Cycle {
    
    // prints the aliquot cycle starting at n
    public static void printCycle(int n) {
        int current = n;
        do {
            StdOut.print(current + " ");
            current = Perfect.aliquot(current);
        } while (current != n);
    }
    
    // read numbers from StdIn and prints info about their cuddliness
    public static void main(String[] args) {
        while (!StdIn.isEmpty()) {
            int n = StdIn.readInt();
            
            // no need to calculate the period more than once
            int period = Cuddly.aPeriod(n);
            
            if (period == -1) {
                StdOut.println(n + " is not cuddly");
            } else if (period ==  1) {
                StdOut.println(n + " is perfect");
            } else if (period ==  2) {
                StdOut.print(n + " is amicable: ");
                printCycle(n);
                StdOut.println();
            } else {
                StdOut.print(n + " is sociable: ");
                printCycle(n);
                StdOut.println();
            }
        }
    }
}