Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- signed long long n,x,p,a[30], c;
- /*
- where: n = user input
- x = value of n
- p = variable where the power is stored
- a = array where the prime factors are stored
- c = counter for the array
- */
- while(cin >> n){
- x = n;
- c = 0; // set it to 0 so a[30] starts at index 0
- p = 1; // set the power to 1
- if((n <= 1) || (n > 4294967295))
- cout << n << " unexpected input" << endl;
- else{
- cout << n << " =";
- for(int i = 2; i <= x; i++){
- if(x%i == 0){
- x = x/i;
- a[c] = i;
- if(a[c-1] == a[c]){
- p = p++;
- if(x == 1)
- cout << "^" << p;
- }
- else{
- if((p > 1) && (a[c] != a[c-1])){
- cout << "^" << p << " " << i;
- p = 1;
- }
- else
- cout << " " << i;
- }
- i = 1;
- c++;
- }
- }
- cout << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement