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.
# Enter your code here. Read input from STDIN. Print output to STDOUTfromfunctoolsimportreducem=1000000007defmul_m(a,b):returna*b%mdefzpow(a,b,m):return0ifb==0elsepow(a,b,m)n=int(input())a=[0]*nb=[0]*np=[0]*nforiinrange(n):p[i],b[i],a[i]=map(int,input().split())B=reduce(mul_m,[pow(p[i],b[i],m)foriinrange(n)])ifall(a[i]==b[i]foriinrange(n)):print(B*2%m)else:print(B*reduce(mul_m,[1+zpow(p[i],a[i]-b[i],m)foriinrange(n)])%m)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Manasa and Calculations
You are viewing a single comment's thread. Return to all comments →