You are viewing a single comment's thread. Return to all comments →
Python3 solution
from functools import reduce def baseconv(n, b): newbase = [] if n < b: return 0 if n == b: return [1] while True: r = n % b newbase.insert(0, r) n = n // b if n == 0: break return newbase t = int(input()) for i in range(t): n, p = map(int, input().split()) base = baseconv(n, p) nonzeros = reduce(lambda x, y: x * y, (z + 1 for z in base)) print(n - nonzeros + 1)
Seems like cookies are disabled on this browser, please enable them to open this website
Binomial Coefficients
You are viewing a single comment's thread. Return to all comments →
Python3 solution