fork download
  1. #include <iostream>
  2. using namespace std;
  3. #include <bits/stdc++.h>
  4. #include<math.h>
  5.  
  6. int main() {
  7. // your code goes here
  8. unordered_map<int,int>freq;
  9. int n;
  10. cin>>n;
  11. int i=2;
  12. while(n%i==0)
  13. {
  14. freq[i]++;
  15. n=n/i;
  16. }
  17.  
  18. for(i=3;i<=sqrt(n);i=i+2)
  19. {
  20. while(n%i==0)
  21. {
  22. freq[i]++;
  23. n=n/i;
  24. }
  25. }
  26.  
  27. for(auto itr=freq.begin();itr!=freq.end();++itr){
  28. cout<<itr->first<<" "<<itr->second;
  29. cout<<"\n";
  30. }
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 5256KB
stdin
18
stdout
3 2
2 1