Advertisement
unknown_0711

Untitled

Oct 2nd, 2022
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. public class Main
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. Scanner sc = new Scanner(System.in);
  9. int n = sc.nextInt();
  10. int k = sc.nextInt();
  11. k%=16;
  12. int []bit= new int[16];
  13. if(k==0){
  14. System.out.print(n+" "+n);
  15. return;
  16. }
  17. for(int i=0;i<16;i++)
  18. {
  19. bit[i]=n%2; n/=2;
  20. }
  21. int left=0;
  22. int one=1;
  23. for(int i=16-k;i<16;i++){
  24. left+=bit[i]*one;
  25. one*=2;
  26. }
  27. for(int i=0;i<16-k;i++){
  28. left+=bit[i]*one;
  29. one*=2;
  30. }
  31. System.out.print(left+" ");
  32. // 1101001
  33. // 1101 001 -> 001 1101
  34. one=1;
  35. int right=0;
  36. for(int i=k;i<16;i++){
  37. right+=bit[i]*one;
  38. one*=2;
  39. }
  40. for(int i=0;i<k;i++){
  41. right+=bit[i]*one;
  42. one*=2;
  43. }
  44. System.out.print(right);
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement