Given a number N, the task is to check whether the product of digits at even places of a number is divisible by K. If it is divisible, output “YES” otherwise output “NO”.

**Examples:**

Input:N = 5478, K = 5Output:YES Since, 5 * 7 = 35, which is divisible by 5Input:N = 19270, K = 2Output:NO

**Approach:**

- Find product of digits at even places from right to left.
- Then check the divisibility by taking it’s modulo with ‘K’
- If modulo gives 0, output YES, otherwise output NO

Below is the implementation of the above approach:

## C++

`// C++ implementation of the above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// below function checks whether ` `// product of digits at even places ` `// is divisible by K ` `bool` `productDivisible(` `int` `n, ` `int` `k) ` `{ ` ` ` `int` `product = 1, position = 1; ` ` ` `while` `(n > 0) { ` ` ` ` ` `// if position is even ` ` ` `if` `(position % 2 == 0) ` ` ` `product *= n % 10; ` ` ` `n = n / 10; ` ` ` `position++; ` ` ` `} ` ` ` ` ` `if` `(product % k == 0) ` ` ` `return` `true` `; ` ` ` `return` `false` `; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 321922; ` ` ` `int` `k = 3; ` ` ` ` ` `if` `(productDivisible(n, k)) ` ` ` `cout << ` `"YES"` `; ` ` ` `else` ` ` `cout << ` `"NO"` `; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// JAVA implementation of the above approach ` `class` `GFG { ` `// below function checks whether ` `// product of digits at even places ` `// is divisible by K ` ` ` ` ` `static` `boolean` `productDivisible(` `int` `n, ` `int` `k) { ` ` ` `int` `product = ` `1` `, position = ` `1` `; ` ` ` `while` `(n > ` `0` `) { ` ` ` ` ` `// if position is even ` ` ` `if` `(position % ` `2` `== ` `0` `) { ` ` ` `product *= n % ` `10` `; ` ` ` `} ` ` ` `n = n / ` `10` `; ` ` ` `position++; ` ` ` `} ` ` ` ` ` `if` `(product % k == ` `0` `) { ` ` ` `return` `true` `; ` ` ` `} ` ` ` `return` `false` `; ` ` ` `} ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String[] args) { ` ` ` `int` `n = ` `321922` `; ` ` ` `int` `k = ` `3` `; ` ` ` ` ` `if` `(productDivisible(n, k)) { ` ` ` `System.out.println(` `"YES"` `); ` ` ` `} ` `else` `{ ` ` ` `System.out.println(` `"NO"` `); ` ` ` `} ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the ` `# above approach ` ` ` `# below function checks whether ` `# product of digits at even places ` `# is divisible by K ` `def` `productDivisible(n, k): ` ` ` `product ` `=` `1` ` ` `position ` `=` `1` ` ` `while` `n > ` `0` `: ` ` ` ` ` `# if position is even ` ` ` `if` `position ` `%` `2` `=` `=` `0` `: ` ` ` `product ` `*` `=` `n ` `%` `10` ` ` `n ` `=` `n ` `/` `10` ` ` `position ` `+` `=` `1` ` ` `if` `product ` `%` `k ` `=` `=` `0` `: ` ` ` `return` `True` ` ` `return` `False` ` ` `# Driver code ` `n ` `=` `321922` `k ` `=` `3` `if` `productDivisible(n, k) ` `=` `=` `True` `: ` ` ` `print` `(` `"YES"` `) ` `else` `: ` ` ` `print` `(` `"NO"` `) ` ` ` `# This code is contributed ` `# by Shrikant13 ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the above approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` `// below function checks whether ` `// product of digits at even places ` `// is divisible by K ` `static` `bool` `productDivisible(` `int` `n, ` `int` `k) ` `{ ` ` ` `int` `product = 1, position = 1; ` ` ` `while` `(n > 0) ` ` ` `{ ` ` ` ` ` `// if position is even ` ` ` `if` `(position % 2 == 0) ` ` ` `product *= n % 10; ` ` ` `n = n / 10; ` ` ` `position++; ` ` ` `} ` ` ` ` ` `if` `(product % k == 0) ` ` ` `return` `true` `; ` ` ` `return` `false` `; ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main() ` `{ ` ` ` `int` `n = 321922; ` ` ` `int` `k = 3; ` ` ` ` ` `if` `(productDivisible(n, k)) ` ` ` `Console.WriteLine(` `"YES"` `); ` ` ` `else` ` ` `Console.WriteLine(` `"NO"` `); ` `} ` `} ` ` ` `// This code is contributed ` `// by Akanksha Rai(Abby_akku) ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the ` `// above approach ` ` ` `// Below function checks whether ` `// product of digits at even places ` `// is divisible by K ` `function` `productDivisible(` `$n` `, ` `$k` `) ` `{ ` ` ` `$product` `= 1; ` ` ` `$position` `= 1; ` ` ` `while` `(` `$n` `> 0) ` ` ` `{ ` ` ` ` ` `// if position is even ` ` ` `if` `(` `$position` `% 2 == 0) ` ` ` `$product` `*= ` `$n` `% 10; ` ` ` `$n` `= (int)(` `$n` `/ 10); ` ` ` `$position` `++; ` ` ` `} ` ` ` ` ` `if` `(` `$product` `% ` `$k` `== 0) ` ` ` `return` `true; ` ` ` `return` `false; ` `} ` ` ` `// Driver code ` `$n` `= 321922; ` `$k` `= 3; ` ` ` `if` `(productDivisible(` `$n` `, ` `$k` `)) ` ` ` `echo` `"YES"` `; ` `else` ` ` `echo` `"NO"` `; ` ` ` `// This code is contributed by mits ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

YES

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:

- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Check whether sum of digits at odd places of a number is divisible by K
- Check if product of digits of a number at even and odd places is equal
- Check if the sum of digits of number is divisible by all of its digits
- Program to check if a number is divisible by any of its digits
- Program to check if a number is divisible by sum of its digits
- Check if N is divisible by a number which is composed of the digits from the set {A, B}
- Given a large number, check if a subsequence of digits is divisible by 8
- Check if the number formed by the last digits of N numbers is divisible by 10 or not
- Find the sum of digits of a number at even and odd places
- Primality test for the sum of digits at odd places of a number
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Check if product of first N natural numbers is divisible by their sum
- Largest number with the given set of N digits that is divisible by 2, 3 and 5
- Find N digits number which is divisible by D
- Smallest number with sum of digits as N and divisible by 10^N
- Number of digits to be removed to make a number divisible by 3
- Count of numbers in range which are divisible by M and have digit D at odd places
- Find a N-digit number such that it is not divisible by any of its digits
- Number of integers in a range [L, R] which are divisible by exactly K of it's digits

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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.