fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc=new Scanner(System.in);
  14. int n=sc.nextInt();
  15. HashMap<Integer,Integer> map=new HashMap<>();
  16. while(n%2==0){
  17. map.put(2,map.getOrDefault(2,0)+1);
  18. n=n/2;
  19. }
  20. for(int i=3;i*i<=n;i=i+2){
  21. while(n%i==0){
  22. map.put(i,map.getOrDefault(i,0)+1);
  23. n=n/i;
  24. }
  25.  
  26.  
  27. }
  28. if(n>2){
  29. map.put(n,map.getOrDefault(n,0)+1);
  30. }
  31. for(int k:map.keySet()){
  32. System.out.println(k + " "+ map.get(k));
  33. }
  34.  
  35.  
  36. }
  37. }
Success #stdin #stdout 0.15s 21840KB
stdin
18
stdout
2 1
3 2