fork download
  1. #include <iostream>
  2. using namespace std;
  3. #include<bits/stdc++.h>
  4.  
  5. typedef long long int ll;
  6.  
  7. map<ll,ll> gen_primeFactors(int n ){
  8. map<ll,ll>pf;
  9. while(n%2==0){
  10. pf[2]++;
  11. n/=2;
  12. }
  13. for(int i = 3 ; i<=sqrt(n);i=i+2){
  14. while(n%i==0){
  15. pf[i]++;
  16. n/=i;
  17. }
  18.  
  19. }
  20. if(n>2){ //to handle the case when n is a prime number greater than 2
  21. pf[n]++;
  22. }
  23. return pf;
  24.  
  25. }
  26.  
  27. int main() {
  28. // your code goes here
  29. int n ;
  30. cin>>n ;
  31. map<ll,ll>pf=gen_primeFactors(n);
  32. for(auto &p :pf){
  33. cout<<p.first<<"^"<<p.second<<".";
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5296KB
stdin
44
stdout
2^2.11^1.