Check whether a number has consecutive 0’s in the given base or not

def hasConsecutiveZeroes(N, K):

z = toK(N, K)

if (check(z)):

print("Yes")

else:

print("No")

def toK(N, K):

w = 1

s = 0

while (N != 0):

r = N % K

N = N//K

s = r * w + s

w = 10

return s

def check(N):

fl = False

while (N != 0):

r = N % 10

N = N//10

if (fl == True and r == 0):

return False

if (r > 0):

fl = False

continue

fl = True

return True

N, K = 15, 8

hasConsecutiveZeroes(N, K)


Program for Number of solutions to Modular Equations

import math

def calculateDivisors (A, B):

N = A - B

noOfDivisors = 0

a = math.sqrt(N)

for i in range(1, int(a + 1)):

if ((N % i == 0)):

if (i > B):

noOfDivisors +=1

if ((N / i) != i and (N / i) > B):

noOfDivisors += 1;

return noOfDivisors

def numberOfPossibleWaysUtil (A, B):

if (A == B):

return -1

if (A < B):

return 0

noOfDivisors = 0

noOfDivisors = calculateDivisors;

return noOfDivisors

def numberOfPossibleWays(A, B):

noOfSolutions = numberOfPossibleWaysUtil(A, B)

if (noOfSolutions == -1):

print ("For A = " , A , " and B = " , B

, ", X can take Infinitely many values"

, " greater than " , A)

else:

print ("For A = " , A , " and B = " , B

, ", X can take " , noOfSolutions

, " values")

A = 26

B = 2

numberOfPossibleWays(A, B)

A = 21

B = 5

numberOfPossibleWays(A, B)