FACT0 - Integer Factorization (15 digits)
#include <iostream>
using namespace std;
int main()
{
long long int n;
int c;
while(true)
{
cin >> n;
if(n == 0)
break;
c = 0;
while(!(n & 1))
{
n = n / 2;
c++;
}
if(c)
cout << "2^" << c << " ";
for(long long i = 3; i * i <= n; i += 2)
{
c = 0;
while(n % i == 0)
{
n = n / i;
c++;
}
if(c)
cout << i << "^" << c << " ";
}
if(n != 1)
cout << n << "^1";
cout << endl;
}
return 0;
}
Comments
Post a Comment