#include<bits/stdc++.h>
#define N 112990000
#define ll unsigned long long int
using namespace std;
int p[N+1];
vector<ll>a;
void prime()
{
ll i, j;
ll l = sqrt(N);
p[0] = p[1] = 1;
a.push_back(2);
for(i=4; i<=N; i+=2)
{
p[i] = 1;
}
for(i=3; i<=N; i+=2)
{
if(p[i] == 0)
{
a.push_back(i);
if(i<=l)
{
for(j=i*i; j<=N; j+=i*2)
p[j] = 1;
}
}
}
}
vector<ll>b;
void primeFactorize(ll n)
{
ll i, j;
ll l = sqrt(n);
for(i=0;a[i]<=l && n > 1;i++)
{
if(n%a[i] == 0)
{
while(n%a[i] == 0)
{
n/=a[i];
b.push_back(a[i]);
}
}
}
if(n>1)
b.push_back(n);
}
int main()
{
prime();
long long int n;
ll j = 1;
while(1)
{
if(j > 1)
{
cout << endl;
}
j++;
cin >> n;
if(n < 0)
break;
primeFactorize(n);
for(ll i = 0; i<b.size(); i++)
{
cout <<" " << b[i] << endl;
}
b.clear();
}
return 0;
}
#define N 112990000
#define ll unsigned long long int
using namespace std;
int p[N+1];
vector<ll>a;
void prime()
{
ll i, j;
ll l = sqrt(N);
p[0] = p[1] = 1;
a.push_back(2);
for(i=4; i<=N; i+=2)
{
p[i] = 1;
}
for(i=3; i<=N; i+=2)
{
if(p[i] == 0)
{
a.push_back(i);
if(i<=l)
{
for(j=i*i; j<=N; j+=i*2)
p[j] = 1;
}
}
}
}
vector<ll>b;
void primeFactorize(ll n)
{
ll i, j;
ll l = sqrt(n);
for(i=0;a[i]<=l && n > 1;i++)
{
if(n%a[i] == 0)
{
while(n%a[i] == 0)
{
n/=a[i];
b.push_back(a[i]);
}
}
}
if(n>1)
b.push_back(n);
}
int main()
{
prime();
long long int n;
ll j = 1;
while(1)
{
if(j > 1)
{
cout << endl;
}
j++;
cin >> n;
if(n < 0)
break;
primeFactorize(n);
for(ll i = 0; i<b.size(); i++)
{
cout <<" " << b[i] << endl;
}
b.clear();
}
return 0;
}
Comments
Post a Comment