Răspuns:
#include <iostream>
using namespace std;
int main()
{
int n, d;
cin >> d;
int nr, gasit=0, b;
n=1;
while (gasit==0 && n<10000000) {
nr=0;
for (b=1; b*b<n; b++) {
if (n%b==0) {
nr=nr+2;
}
}
if (b*b==n) ++nr;
if (nr==d) {
gasit=1;
}
else ++n;
}
if (gasit) {
cout << n << endl;
for (b=1; b<=n/2; b++) {
if (n%b==0) cout << b << " ";
}
cout << n;
}
else {
cout << "nu exista";
}
return 0;
}
Explicație: