I have done a lot of work on this but couldnt find the answer for larger test cases
Problem statement
In mathematics, binomial coefficients are a family of positive integers that occur as coefficients in the binomial theorem. C(n,k) denotes the number of ways of choosing k objects from n different objects.
However when n and k are too large, we often save them after modulo operation by a prime number P. Please calculate how many binomial coefficients of n become to 0 after modulo by P.
Input
The first of input is an integer T , the number of test cases.
Each of the following T lines contains 2 integers, n and prime P.
Output
For each test case, output a line contains the number of \tbinom nks (0<=k<=n) each of which after modulo operation by P is 0.
Sample Input
3
2 2
3 2
4 3
Sample Output
1
0
1
Constraints:
- T is less than 100
- n is less than 10^500.
- P is less than 10^9.
Attemted solution
i have completed this by using remainder theorem in binomial coeffecients
#C(n,m) mod p
#n=l*p+t
#m=m*p+s
#then C(n,r) mod p=0 when (t<s or t=0)
inp1 = raw_input()
N=int(inp1)
result=[]
for i in range(N):
inp = raw_input()
a, b = [long(x) for x in inp.split(' ')]
j=0
#n=lp+t
t=a%b
t=t+1
l=a/b
j=l*(b-t)
result.append(j)
for i in range(N):
print result[i]
above condition is satisfied for small numbers
sample test case
n=18794630773460178101742670493883191390743597826923079533199667903991430393463990462500322752062869664969026409174076912867222446746310051635510258172105034070506806228555577773599018819952185016092141574603857551738968553782672643049704163674318579695215402562964641111900657274032612661770435202254364177910753450214277150377049334509093906874400306682949871260040370515062243982543271073443613028133844603853807066311479739789908983610180228625059956919930500586048799830730348503994503184106117058
p= 177080341
my output is
2296508200406431043037217853758906667313789305876262916681342008001095232916608835588093082038358975456171743147798282523487485386336553910277635713985851142371010771392102277877640275384064735398164190968282400640398659343189330639672472613876688344609533340662724884373078840434716174167873375700938597411315754265893890741730938202927739246687866166994143001482839656000969674716959277820008958538229366474207686428750934149471409162993083541475267772950721250234982686128039722553219836725588488
expected output is
18794630773460178101742635959946548665553041135822283621364103266511586625905046107130878283695016799933475657268010472422112556606280021574002866456544310584537519228161286450725015989697306855581489155139723025246780552510467580791551824827637581156204185887378181074365453150481221030356075255000460025095384537510111086396988416046942446776262625161326885418101128327416784858513888616089287333560469336094431461981368825028447505354473183546488856594449627370807707483671453574074503184106117059