Sorry I did not understand the exponent part. What is v2?
And is this only for even numbers? Because if we do 7 XOR 8 it is 1111 which isn’t a power of 2
Thanks
Hello, I can’t seem to understand the continuous sequence 0000111100001111…
I mean I can’t understand the way the pattern is shown? is it grouped by 3 bits of x, x+1, x+2, x+3?
If I do power(2,n) then divide it by 2 it gives wrong but power(2,n-1) works, why?
Like (2^n)/2 and 2^(n-1) are same but in some cases mismatch plz explain. Thanks! @taran_1407
This is a simple solution in c++:
After analysis for some test cases and some value of x and n. I came to the conclusion that finally the answer will always be 2 to the power of (n-1).
#include<bits/stdc++.h>
using namespace std;
int power(int a,int b){
if(b==0){
return 1;
}
long temp=power(a,b/2);
long result=(temptemp)%1000000007;
if(b%2==1){
result=(resulta)%1000000007;
}
return result%1000000007;
}
int main(){
int t,n;
cin>>t;
for(int i=0;i<t;i++){
cin>>n;
int ans=power(2,n-1);
bro…i didn’t get this…can you please elaborate…i was having same problem…when i wrote n/2 it gave me WA…and then it gave me AC when i wrote n-1. Please explain me it would ve a great help.
~From Beginner
i saw the solution from the video editorial and I didn’t understand one thing what’s the use of %MOD like he is storing double of previous answers
That is if n = 4, so it is storing ans[3] × 2 at n = 4
Ans of n = 4 is …4× 2 = 8. I don’t get what’s the use of MOD here? like there was given in the Q to use 10^9+7 since the input were larget but what is the use of MOD in this line ?
" ans[i] = (ans[i-1]*2)% MOD; " #include