// Arup Guha
// 2/3/2026
// Uses information about perfect numbers and the MathFunctions class
// to print out some perfect numbers.

import java.util.*;

public class PerfectNums {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		
		// Read the number.
		System.out.println("How many perfect numbers do you want printed out (please answer 1 to 5.)?");
		int n = stdin.nextInt();
		
		// Error checking to avoid overflow!
		while (n<1 || n>5) {
			System.out.println("Sorry, that's not valid. Please enter an integer in between 1 and 5, inclusive.");
			n = stdin.nextInt();
		}
		
		// Here we use the fact that all known perfect numbers are of the form 2^(n-1)*(2^n-1).
		int count = 0;
		for (int p=1; count<n; p++) {
			
			// Try this one out.
			int firstTerm = MathFunctions.intPow(2, p-1);
			int tryval = firstTerm*(2*firstTerm-1);
			
			// Ta da!
			if (MathFunctions.isPerfect(tryval)) {
				System.out.println((count+1)+" perfect number is "+tryval);
				count++;
			}
		}
		
	}
}