fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7. int sn = sqrt(n);
  8. bool first_output = true;
  9. for(int i = 2; i <= sn; i++){
  10. if(n % i == 0){
  11. int cnt = 0;
  12. while(n % i == 0){
  13. n /= i;
  14. cnt++;
  15. }
  16.  
  17. if(!first_output){
  18. cout << " * ";
  19. }
  20. cout << i;
  21. if(cnt > 1){
  22. cout << '^' << cnt;
  23. }
  24.  
  25. first_output = false;
  26. }
  27. }
  28. if(n != 1 || first_output){
  29. if(!first_output){
  30. cout << " * ";
  31. }
  32. cout << n;
  33. }
  34. cout << endl;
  35. return 0;
  36. }
Success #stdin #stdout 0s 5320KB
stdin
2000000014
stdout
2 * 1000000007