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 STDOUTMOD=10**9+7defsieve(n):l=[True]*nps=[]foriinrange(2,n):ifl[i]:ps.append(i)forjinrange(i*i,n,i):l[j]=Falsereturnpsprimes=sieve(10**4)defpascal(n):rows=[[1]]foriinrange(n):rows.append([(a+b)%MODfor(a,b)inzip(rows[-1]+[0],[0]+rows[-1])])returnrowsbinom_=pascal(3005)defbinom(n,k):ifk<0ork>n:return0returnbinom_[n][k]defprime_exploration(p,n,d):ifd==1:returnp**ns=0pp=1forkinrange(n+1):s+=pp*binom(n-k+d-2,d-2)pp=p*pp%MODreturns%MODdefdivisor_exploration(m,a,d):prod=1foriinrange(m):x=prime_exploration(primes[i],a+i+1,d)prod=prod*x%MODreturnprodforiinrange(int(input())):print(divisor_exploration(*map(int,input().split())))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Divisor Exploration 3
You are viewing a single comment's thread. Return to all comments →
PyPy 3 solution