Created
October 17, 2022 20:04
-
-
Save ZhouYang1993/161ce824d17cadbc8d98ff514b06dcc7 to your computer and use it in GitHub Desktop.
LeetCode 2438. Range Product Queries of Powers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def productQueries(self, n: int, queries): | |
bn = bin(n)[2:][::-1] | |
powers = [] | |
for i, v in enumerate(bn): | |
if v == '1': | |
powers.append(i) | |
ans = [] | |
for l, r in queries: | |
t = 0 | |
for i in range(l, r + 1): | |
t += powers[i] | |
ans.append(2 ** t % (10 ** 9 + 7)) | |
return ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment