We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Some things to notice:
Since we only need to take note whether find(x,y) is odd or even, and since find(x,y) function is just repeated exponentiation with base arr[x]:
1. the result will be even if arr[x-1] (-1 because indices start from 1) is even and the next array element arr[x] is not zero (otherwise we end up getting 1).
2. the result will be odd if arr[x-1] is odd or if arr[x-1] is even and arr[x] is odd (as I explained in 1 above). Then the code is simple to be honest:
In C++:
Even Odd Query
You are viewing a single comment's thread. Return to all comments →
Some things to notice: Since we only need to take note whether find(x,y) is odd or even, and since find(x,y) function is just repeated exponentiation with base arr[x]: 1. the result will be even if arr[x-1] (-1 because indices start from 1) is even and the next array element arr[x] is not zero (otherwise we end up getting 1). 2. the result will be odd if arr[x-1] is odd or if arr[x-1] is even and arr[x] is odd (as I explained in 1 above). Then the code is simple to be honest: In C++: