A couple optimizations for you stiltzkin
when you find a prime remove as many of that prime as possible from the list then start searching at that number plus 2, don't start back at 2. Also don't increment i by one instead increament it by 2 (making sure it is odd to start).
Here is what I came up with in 3 minutes. I don't actually save the primes but one could easily add the code to save them in a few minutes.
Code:
#include <iostream>
using namespace std;
int main()
{
unsigned int n;
cout << "Enter a positive number: ";
cin >> n;
cout << "The prime factors are:\n1 ";
//remove 2's
while(n%2==0)
{
cout << "2 ";
n/=2;
}
int p=3;
//remove odd numbers
while(n!=1)
{
while(n%p==0)
{
cout << p << " ";
n/=p;
}
p+=2;
}
cout << endl;
}