Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- public class Main
- {
- public static void main (String[] args) throws java.lang.Exception
- {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int k = sc.nextInt();
- k%=16;
- int []bit= new int[16];
- if(k==0){
- System.out.print(n+" "+n);
- return;
- }
- for(int i=0;i<16;i++)
- {
- bit[i]=n%2; n/=2;
- }
- int left=0;
- int one=1;
- for(int i=16-k;i<16;i++){
- left+=bit[i]*one;
- one*=2;
- }
- for(int i=0;i<16-k;i++){
- left+=bit[i]*one;
- one*=2;
- }
- System.out.print(left+" ");
- // 1101001
- // 1101 001 -> 001 1101
- one=1;
- int right=0;
- for(int i=k;i<16;i++){
- right+=bit[i]*one;
- one*=2;
- }
- for(int i=0;i<k;i++){
- right+=bit[i]*one;
- one*=2;
- }
- System.out.print(right);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement