Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5.  
  6. signed long long n,x,p,a[30], c;
  7. /*
  8. where: n = user input
  9. x = value of n
  10. p = variable where the power is stored
  11. a = array where the prime factors are stored
  12. c = counter for the array
  13. */
  14.  
  15. while(cin >> n){
  16.  
  17. x = n;
  18. c = 0; // set it to 0 so a[30] starts at index 0
  19. p = 1; // set the power to 1
  20.  
  21. if((n <= 1) || (n > 4294967295))
  22. cout << n << " unexpected input" << endl;
  23.  
  24. else{
  25. cout << n << " =";
  26.  
  27. for(int i = 2; i <= x; i++){
  28.  
  29. if(x%i == 0){
  30.  
  31. x = x/i;
  32. a[c] = i;
  33.  
  34. if(a[c-1] == a[c]){
  35.  
  36. p = p++;
  37.  
  38. if(x == 1)
  39. cout << "^" << p;
  40. }
  41. else{
  42. if((p > 1) && (a[c] != a[c-1])){
  43. cout << "^" << p << " " << i;
  44. p = 1;
  45. }
  46. else
  47. cout << " " << i;
  48. }
  49. i = 1;
  50. c++;
  51. }
  52. }
  53. cout << endl;
  54. }
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement