fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int n;
  8. cin>>n;
  9.  
  10. unordered_map<int,int> mpp;
  11.  
  12. while(n%2==0){
  13. mpp[2]++;
  14. n=n/2;
  15. }
  16.  
  17. for(int i=3;i<=sqrt(n);i=i+2){
  18. while(n%i==0){
  19. mpp[i]++;
  20. n=n/i;
  21.  
  22. }
  23. }
  24.  
  25. if(n>2){
  26. mpp[n]++;
  27.  
  28. }
  29.  
  30. for(auto it : mpp) {
  31. cout << it.first << "^" << it.second << " ";
  32. }
  33.  
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 5332KB
stdin
24
stdout
3^1 2^3