Two integers n and k are given. Our task is to print K-rounding of n. K-rounding is the minimum positive integer X, such that x ends with k or more zeros and is divisible by n.

**Examples :**

Input : n = 30, k = 3. Output : 3000 3000 is the smallest number that has at-least k 0s and is divisible by n. Input : n = 375, k = 4. Output : 30000

**Method 1 :**

The brute force approach is to start with result = 10^{k}. Check if result is divided by n. If yes, it’s the answer, else increase it by 10^{k}

**Method 2 :** The efficient approach is to calculate the LCM of 10^{k} and n.

Suppose, n = 375, k = 4.

result = 10000.

Now, LCM of 375 and 10000 is the lowest number divided by both of them.

It will contain k or more zeros (because it is multiple of 10^{k}) and will be a multiple of n as well.

Below is the implementation :

## C++

`// CPP code to print K-rounded value of n ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to compute the rounded value ` `long` `long` `getRounding(` `long` `long` `n, ` `long` `long` `k) ` `{ ` ` ` `long` `long` `rounding = ` `pow` `(10, k); ` ` ` ` ` `// Computing GCD ` ` ` `long` `long` `result = __gcd(rounding, n); ` ` ` ` ` `// Returning LCM (GCD * LCM = n * k) ` ` ` `return` `((rounding * n) / result); ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` ` ` `long` `long` `n = 375, k = 4; ` ` ` ` ` `// Function call ` ` ` `cout << getRounding(n, k); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// JAVA Code For Smallest number divisible by ` `// n and has at-least k trailing zeros ` `import` `java.util.*; ` ` ` `class` `GFG { ` ` ` ` ` `// Function to find gcd ` ` ` `static` `long` `gcd(` `long` `a, ` `long` `b) ` ` ` `{ ` ` ` `// Everything divides 0 ` ` ` `if` `(a == ` `0` `|| b == ` `0` `) ` ` ` `return` `0` `; ` ` ` ` ` `// base case ` ` ` `if` `(a == b) ` ` ` `return` `a; ` ` ` ` ` `// a is greater ` ` ` `if` `(a > b) ` ` ` `return` `gcd(a-b, b); ` ` ` `return` `gcd(a, b-a); ` ` ` `} ` ` ` ` ` `// Function to compute the rounded value ` ` ` `public` `static` `long` `getRounding(` `long` `n, ` `long` `k) ` ` ` `{ ` ` ` `long` `rounding = (` `long` `)Math.pow(` `10` `, k); ` ` ` ` ` `// Computing GCD ` ` ` `long` `result = gcd(rounding, n); ` ` ` ` ` `// Returning LCM (GCD * LCM = n * k) ` ` ` `return` `((rounding * n) / result); ` ` ` `} ` ` ` ` ` `/* Driver program to test above function */` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` `long` `n = ` `375` `, k = ` `4` `; ` ` ` ` ` `// Function call ` ` ` `System.out.println( getRounding(n, k)); ` ` ` ` ` `} ` `} ` ` ` `// This code is contributed by Arnav Kr. Mandal. ` |

*chevron_right*

*filter_none*

## Python3

`# python Code For Smallest number ` `# divisible by n and has ` `# at-least k trailing zeros ` ` ` `# Function to find gcd ` `def` `gcd(a, b): ` ` ` ` ` `# Everything divides 0 ` ` ` `if` `(a ` `=` `=` `0` `or` `b ` `=` `=` `0` `): ` ` ` `return` `0` ` ` ` ` `# base case ` ` ` `if` `(a ` `=` `=` `b): ` ` ` `return` `a ` ` ` ` ` `# a is greater ` ` ` `if` `(a > b): ` ` ` `return` `gcd(a ` `-` `b, b) ` ` ` ` ` `return` `gcd(a, b ` `-` `a) ` ` ` `# Function to compute the ` `# rounded value ` `def` `getRounding(n, k): ` ` ` ` ` `rounding ` `=` `pow` `(` `10` `, k); ` ` ` ` ` `# Computing GCD ` ` ` `result ` `=` `gcd(rounding, n) ` ` ` ` ` `# Returning LCM (GCD * LCM ` ` ` `# = n * k) ` ` ` `return` `((rounding ` `*` `n) ` `/` `result) ` ` ` `# Driver Code ` ` ` `n ` `=` `375` `k ` `=` `4` ` ` `# Function call ` `print` `( ` `int` `(getRounding(n, k))) ` ` ` `# This code is contributed by Sam007 ` |

*chevron_right*

*filter_none*

## C#

`// C# Code For Smallest number ` `// divisible by n and has ` `// at-least k trailing zeros ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// Function to find gcd ` ` ` `static` `long` `gcd(` `long` `a, ` `long` `b) ` ` ` `{ ` ` ` ` ` `// Everything divides 0 ` ` ` `if` `(a == 0 || b == 0) ` ` ` `return` `0; ` ` ` ` ` `// base case ` ` ` `if` `(a == b) ` ` ` `return` `a; ` ` ` ` ` `// a is greater ` ` ` `if` `(a > b) ` ` ` `return` `gcd(a - b, b); ` ` ` `return` `gcd(a, b - a); ` ` ` `} ` ` ` ` ` `// Function to compute the rounded value ` ` ` `public` `static` `long` `getRounding(` `long` `n, ` `long` `k) ` ` ` `{ ` ` ` `long` `rounding = (` `long` `)Math.Pow(10, k); ` ` ` ` ` `// Computing GCD ` ` ` `long` `result = gcd(rounding, n); ` ` ` ` ` `// Returning LCM (GCD * LCM = n * k) ` ` ` `return` `((rounding * n) / result); ` ` ` `} ` ` ` ` ` `// Driver Code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `long` `n = 375, k = 4; ` ` ` ` ` `// Function call ` ` ` `Console.Write( getRounding(n, k)); ` ` ` ` ` `} ` `} ` ` ` `// This code is contributed by Nitin Mittal. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP Code For Smallest number ` `// divisible by n and has ` `// at-least k trailing zeros ` `function` `gcd(` `$a` `, ` `$b` `) ` `{ ` ` ` ` ` `// Everything divides 0 ` ` ` `if` `(` `$a` `== 0 || ` `$b` `== 0) ` ` ` `return` `0; ` ` ` ` ` `// base case ` ` ` `if` `(` `$a` `== ` `$b` `) ` ` ` `return` `$a` `; ` ` ` ` ` `// a is greater ` ` ` `if` `(` `$a` `> ` `$b` `) ` ` ` `return` `gcd(` `$a` `- ` `$b` `, ` `$b` `); ` ` ` `return` `gcd(` `$a` `, ` `$b` `- ` `$a` `); ` `} ` ` ` `// Function to compute ` `// the rounded value ` `function` `getRounding(` `$n` `, ` `$k` `) ` `{ ` ` ` `$rounding` `= ` `intval` `(pow(10, ` `$k` `)); ` ` ` ` ` `// Computing GCD ` ` ` `$result` `= gcd(` `$rounding` `, ` `$n` `); ` ` ` ` ` `// Returning LCM (GCD * LCM = n * k) ` ` ` `return` `intval` `((` `$rounding` `* ` `$n` `) / ` ` ` `$result` `); ` `} ` ` ` `// Driver code ` `$n` `= 375; ` `$k` `= 4; ` ` ` `// Function call ` `echo` `getRounding(` `$n` `, ` `$k` `); ` ` ` `// This code is contributed by Sam007 ` `?> ` |

*chevron_right*

*filter_none*

**Output :**

30000

This article is contributed by **Rohit Thapliyal**. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Find the smallest number X such that X! contains at least Y trailing zeros.
- Count number of trailing zeros in Binary representation of a number using Bitset
- Count number of trailing zeros in product of array
- Count number of trailing zeros in (1^1)*(2^2)*(3^3)*(4^4)*..
- Number of trailing zeros in N * (N - 2) * (N - 4)*....
- Count unique numbers that can be generated from N by adding one and removing trailing zeros
- NFA to accept strings that has atleast one character occurring in a multiple of 3
- Smallest number with at least n trailing zeroes in factorial
- Prove that atleast one of three consecutive even numbers is divisible by 6
- Count pairs (A, B) such that A has X and B has Y number of set bits and A+B = C
- Smallest non-zero substring which has any permutation divisible by 2^K
- Check if it is possible to create a matrix such that every row has A 1s and every column has B 1s
- Largest number with maximum trailing nines which is less than N and greater than N-D
- Count trailing zeroes in factorial of a number
- Trailing number of 0s in product of two factorials
- Number of trailing zeroes in base B representation of N!
- Smallest number greater or equals to N such that it has no odd positioned bit set
- Smallest number whose square has N digits
- Find the integer points (x, y) with Manhattan distance atleast N
- Minimum window size containing atleast P primes in every window of given range