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

Serverless — revolution or another failure

How to run scenario tests in WSO2 API Manager?

4 steps to Android Dot TabItem

The End of a Milestone and the Start of a Journey

TryHackMe Walkthrough | Thompson

(PDF) 破碎的生活:普通德国人经历的20世纪 (从纳粹独裁、二战、大屠杀、冷战到柏林墙倒塌,一幅20世纪德国历史的完整图景,一部折射大时代的“小人物”群像 理想国出品)

Where GDS went wrong and what could be done about it

Merkle Membership Proofs

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

What Is Multithreading | Multithreading Programs In Java

Multithreading

The diamond problem in java is coming due to multiple inheritances.

How to run multiple Java versions (like Java 8, 11 or latest) on Mac machine

Micronaut application in heroku