用优先队列挺OK的
#include<stdio.h>
#include<queue>
#include<cmath>
using namespace std;
priority_queue<int,vector<int>,greater<int> > q;
int main(int n){
scanf("%d",&n);
q.push(1);
for(int i=2;i<=sqrt(n);i++) if(!(n%i)){
q.push(i);
if(n/i!=i) q.push(n/i);
}
if(n!=1) q.push(n);
while(!q.empty()) printf("%d\n",q.top()),q.pop();
return 0;
}