BITWISE TUPLES (BITTUP) Solution — Codechef JuneLong Challenge

Input

  • The first line contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains two integers N and M.

Output

Constraints

  • 1≤T≤10⁵
  • 1≤N,M≤10⁶

Subtasks

Sample Input

4
1 2
2 2
4 2
8 4

Sample Output

1
9
225
228250597

Explanation

/* package codechef; // don't place package name! */import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
static long mod = 1000000007;
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
long a=0,b=0;
a = sc.nextLong();
b = sc.nextLong();
long ians = findPower(2, a)-1;
System.out.println(findPower(ians,b));
}
}

public static long findPower(long a , long b){
if(b==0)
return 1;
else if(b==1)
return a;

if((b%2)==0){
long temp = findPower(a,b/2);
return (temp*temp)%mod;
}
else{
long temp = findPower(a,(b-1)/2);
return ((a*temp)%mod*temp)%mod;
}
}
}

--

--

--

Software Developer ,currently pursuing B.Tech in Information Technology. Electronic Dance Music is love.Also like all phone related technologies

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Create React Native Airbnb-Like App

The Long Arm of the Law — On the Construction of a Single Page Application using JavaScript & Rails

Microsoft Graph API : User Management in Azure AD with .NET Core

https://gxcuf89792.i.lithium.com/t5/image/serverpage/image-id/86459i691A5DADF8A7B2C8/image-size/large?v=1.0&px=999

A Documentation of some errors encountered while using AWS CloudFormation CLI and EC2 Server

terraform destroy a vpc

Setup Jupyter Notebook on your Local Machine and use it from anywhere using this Tool

Datera Storage: Automating Storage Fleet Management @Scale with Ansible

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anubhav Mishra

Anubhav Mishra

Software Developer ,currently pursuing B.Tech in Information Technology. Electronic Dance Music is love.Also like all phone related technologies

More from Medium

Micronaut application in heroku

Class and Object

Flywheel Shooter Software for FRC

JDK vs JRE vs JVM: Key Differences