#include <iostream>
#include <stdexcept>
#include <limits>
using namespace std;

int main(){
	cout << "Divisors of n \n";
	cout << "To exit: n < 0 \n\n";
	while (true) {
		try{
			long n;
			cout << "n = ";
			cin >> n;
			if (cin.fail()){
				throw invalid_argument("Error! You have to enter a natural number within the standard range!");
			}
			if (n>0){
				for (int i=1; i<n+1; i++) {
	    			if (n % i == 0) {
	    				cout << i << endl;
					}
				}				
			} else {
				cout << "The program is terminated. Bye!";
				break;
			}
			cout << endl;
		} catch (const invalid_argument& e){
			cin.clear(); 
            cin.ignore(numeric_limits<streamsize>::max(), '\n'); 
			cout << e.what() << endl << endl;
		}
	}
	return 0;
}
