XOR Equality(XOREQUAL) Solution — Codechef MayLong Challenge

Input

Output

Constraints

Subtasks

Sample Input

2
1
2

Sample Output

1
2

Explanation

import java.util.*;import java.lang.*;import java.io.*;class Codechef{public static void main (String[] args) throws java.lang.Exception{Scanner sc = new Scanner(System.in);int t = sc.nextInt();while(t-- > 0){long n = sc.nextLong();long count = findans(2,n-1,1000000007);System.out.println(count);}}public static long findans(long x, long y, long p){
//doing this for Modular Exponentiation to remove TLE
long res = 1; // Initialize resultx = x%p;if(x==0) return 0;while (y > 0){// If y is odd, multiply x with resultif ((y & 1) != 0)res = (res * x)%p;// y must be even nowy = y >> 1; // y = y/2x = (x * x)%p; // Change x to x^2}return res;}}

--

--

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