XOR Equality(XOREQUAL) Solution — Codechef MayLong Challenge

Input

  • The first line contains an integer T, the number of test cases. Then the test cases follow.
  • The only line of each test case contains a single integer N.

Output

Constraints

  • 1≤T≤10⁵
  • 1≤N≤10⁵

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;}}

--

--

--

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

Sprint 1: Setting Up

Essential Commands For OperatingYour Mac Terminal

Lock-less Coherency Protocol

READ/DOWNLOAD%! Programming PIC Microcontrollers with XC8 FULL BOOK PDF & FULL AUDIOBOOK

Portuguese added as an application language

9 Essential commands to unlock the power of vim

A Day in the Life of a DevOps

How to learn programming if you have zero experience

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

Setting Up Sublime Text 3 for Competitive coding in Java

How to solve the “Fibonacci Number modulo M” Problem in Java

Fibonacci numbers

Remove Zero Sum Consecutive Nodes from Linked List

Search — Algorithm in JAVA