Monday, October 31, 2022

Problem solved - XOR Equality

Hi. As I practice on various coding platforms, I keep on sharing my solutions as a blog post for me to refer back in future and also broadly for anyone searching for the same.

With this, let us begin with today's problem :- 

Problem Name - XOR Equality

Problem Code - XOREQUAL

Problem Link - https://www.codechef.com/submit/XOREQUAL

How I solved it :-

Language used : C++

#include<iostream>
using namespace std;

#define m (int)(1e9+7)

int poww(int base, int expo){
    if(!expo) return 1;
    if(expo==1) return base%m;
    if(expo&1) return (1LL*(base%m)*(poww(base, expo-1)%m))%m;
    return poww((1LL*(base%m)*(base%m))%m, expo/2)%m;
}

void solve(void){
    int n;
    cin>>n;
    cout<<poww(2, n-1)%m<<'\n';
    return;
}

int main(void) {
	// your code goes here
	int t;
	cin>>t;
	while(t--) solve();
	return 0;
}

No comments:

Post a Comment

You may like these:

HANDS ON JAVA(OOP - based uses) (Part-I)

     Practice JAVA like Never Before!                                                                                                     ...