Program to print smallest m digit number divisible by n using Python

by | Aug 15, 2021 | Python Programs

Introduction

The task to find and print the smallest M digit number divisible by N.

Program to print smallest m digit number divisible by n using Python

Program

def result(n, m):
    x = pow(10, m-1)   
    if( x % n == 0):
        print(x)     
    else:
        print((x + n) - ((x + n) % n))   
n = 64 
m = 8 
result(n, m)

Output

Program to print smallest m digit number divisible by n using Python Output

Explanation

In the above code, we have taken the min M digit number as 10…M times. If  min%N is equalled to zero, the min is returned otherwise we compute ((min+N) – ((min+N)%N)) and return the min value divisible by N.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.