Skip to content

Instantly share code, notes, and snippets.

@ZhouYang1993
Created October 17, 2022 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZhouYang1993/161ce824d17cadbc8d98ff514b06dcc7 to your computer and use it in GitHub Desktop.
Save ZhouYang1993/161ce824d17cadbc8d98ff514b06dcc7 to your computer and use it in GitHub Desktop.
LeetCode 2438. Range Product Queries of Powers
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