Facebook
From VENKAT NARASIMAM TENNETI, 1 Year ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 64
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Solution {
  5.  
  6.     public static void main(String[] args) {
  7.         /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
  8.         Scanner sc=new Scanner(System.in);
  9.         long test_case=sc.nextLong();
  10.         while(test_case>0){
  11.             System.out.println(xyBits(sc.nextLong(),sc.nextLong()));
  12.             test_case--;
  13.         }
  14.     }
  15.     private static long xyBits(long x_bit,long y_bit){
  16.         long tot_bits=(x_bit+y_bit-1)%1000000007;
  17.         long num=0;
  18.         for(long i=tot_bits;i>tot_bits-x_bit;i--){
  19.             // num+=(1<<i)%1000000007;
  20.             num+=powof2(2,i);
  21.         }
  22.         return num%1000000007;
  23.     }
  24.     private static long powof2(long x,long y){
  25.         if(x==0 & y==0){
  26.                 return 1;
  27.         }else if(y==0){
  28.                 return 1;
  29.         }else if(x==0){
  30.                 return 0;  
  31.         }else{
  32.             long ans=1;
  33.             while(y>0){
  34.                 if((y&1)==1){
  35.                     ans=(ans*x)%1000000007;
  36.                 }
  37.                 x=(x*x)%1000000007;
  38.                 y=y/2;
  39.             }  
  40.               return ans;
  41.         }
  42.     }
  43. }