Given two integer ‘N’ and ‘K’, the task is to find the sum of digits of ‘N’ at it’s odd places (right to left) and check whether the sum is divisible by ‘K’. If it is divisible, output *YES*, otherwise output *NO*.

**Examples:**

Input:N = 4325, K = 4

Output:YES

Since, 3 + 5 = 8, which is divisible by 4.

Input:N = 1209, K = 3

Output:NO

**Approach:**

- Find the sum of the digits of ‘N’ at odd places (right to left).
- Then check the divisibility of the sum by taking it’s modulo with ‘K’.
- If it is divisible then output ‘YES’, otherwise output ‘NO’.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// function that checks the ` `// divisibility of the sum ` `// of the digits at odd places ` `// of the given number ` `bool` `SumDivisible(` `int` `n, ` `int` `k) ` `{ ` ` ` `int` `sum = 0, position = 1; ` ` ` `while` `(n > 0) { ` ` ` ` ` `// if position is odd ` ` ` `if` `(position % 2 == 1) ` ` ` `sum += n % 10; ` ` ` `n = n / 10; ` ` ` `position++; ` ` ` `} ` ` ` ` ` `if` `(sum % k == 0) ` ` ` `return` `true` `; ` ` ` `return` `false` `; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 592452; ` ` ` `int` `k = 3; ` ` ` ` ` `if` `(SumDivisible(n, k)) ` ` ` `cout << ` `"YES"` `; ` ` ` `else` ` ` `cout << ` `"NO"` `; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `import` `java.util.*; ` ` ` `class` `solution ` `{ ` ` ` `// function that checks the ` `// divisibility of the sum ` `// of the digits at odd places ` `// of the given number ` `static` `boolean` `SumDivisible(` `int` `n, ` `int` `k) ` `{ ` ` ` `int` `sum = ` `0` `, position = ` `1` `; ` ` ` `while` `(n > ` `0` `) { ` ` ` ` ` `// if position is odd ` ` ` `if` `(position % ` `2` `== ` `1` `) ` ` ` `sum += n % ` `10` `; ` ` ` `n = n / ` `10` `; ` ` ` `position++; ` ` ` `} ` ` ` ` ` `if` `(sum % k == ` `0` `) ` ` ` `return` `true` `; ` ` ` `return` `false` `; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String arr[]) ` `{ ` ` ` `int` `n = ` `592452` `; ` ` ` `int` `k = ` `3` `; ` ` ` ` ` `if` `(SumDivisible(n, k)) ` ` ` `System.out.println(` `"YES"` `); ` ` ` `else` ` ` `System.out.println(` `"NO"` `); ` ` ` `} ` `} ` `//This code is contributed by Surendra_Gangwar ` |

*chevron_right*

*filter_none*

## Python 3

`# Python 3 implementation of the approach ` ` ` `# function that checks the divisibility ` `# of the sum of the digits at odd places ` `# of the given number ` `def` `SumDivisible(n, k): ` ` ` ` ` `sum` `=` `0` ` ` `position ` `=` `1` ` ` `while` `(n > ` `0` `) : ` ` ` ` ` `# if position is odd ` ` ` `if` `(position ` `%` `2` `=` `=` `1` `): ` ` ` `sum` `+` `=` `n ` `%` `10` ` ` `n ` `=` `n ` `/` `/` `10` ` ` `position ` `+` `=` `1` ` ` ` ` `if` `(` `sum` `%` `k ` `=` `=` `0` `): ` ` ` `return` `True` ` ` `return` `False` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` `n ` `=` `592452` ` ` `k ` `=` `3` ` ` ` ` `if` `(SumDivisible(n, k)): ` ` ` `print` `(` `"YES"` `) ` ` ` `else` `: ` ` ` `print` `(` `"NO"` `) ` ` ` `# This code is contributed ` `# by ChitraNayal ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` `// function that checks the ` `// divisibility of the sum ` `// of the digits at odd places ` `// of the given number ` `static` `bool` `SumDivisible(` `int` `n, ` `int` `k) ` `{ ` ` ` `int` `sum = 0, position = 1; ` ` ` `while` `(n > 0) ` ` ` `{ ` ` ` ` ` `// if position is odd ` ` ` `if` `(position % 2 == 1) ` ` ` `sum += n % 10; ` ` ` `n = n / 10; ` ` ` `position++; ` ` ` `} ` ` ` ` ` `if` `(sum % k == 0) ` ` ` `return` `true` `; ` ` ` `return` `false` `; ` `} ` ` ` `// Driver code ` `static` `public` `void` `Main () ` `{ ` ` ` `int` `n = 592452; ` ` ` `int` `k = 3; ` ` ` ` ` `if` `(SumDivisible(n, k)) ` ` ` `Console.WriteLine(` `"YES"` `); ` ` ` `else` ` ` `Console.WriteLine(` `"NO"` `); ` `} ` `} ` ` ` `// This code is contributed by Sachin ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the approach ` ` ` `// function that checks the divisibility ` `// of the sum of the digits at odd places ` `// of the given number ` `function` `SumDivisible(` `$n` `, ` `$k` `) ` `{ ` ` ` `$sum` `= 0; ` ` ` `$position` `= 1; ` ` ` `while` `(` `$n` `> 0) ` ` ` `{ ` ` ` ` ` `// if position is odd ` ` ` `if` `(` `$position` `% 2 == 1) ` ` ` `$sum` `+= ` `$n` `% 10; ` ` ` `$n` `= (int)` `$n` `/ 10; ` ` ` `$position` `++; ` ` ` `} ` ` ` ` ` `if` `(` `$sum` `% ` `$k` `== 0) ` ` ` `return` `true; ` ` ` `return` `false; ` `} ` ` ` `// Driver code ` `$n` `= 592452; ` `$k` `= 3; ` ` ` `if` `(SumDivisible(` `$n` `, ` `$k` `)) ` ` ` `echo` `"YES"` `; ` `else` ` ` `echo` `"NO"` `; ` ` ` `// This code is contributed ` `// by Sach_Code ` `?> ` |

*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 product of digits at even 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}
- Check if the number formed by the last digits of N numbers is divisible by 10 or not
- Given a large number, check if a subsequence of digits is divisible by 8
- 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
- Largest number with the given set of N digits that is divisible by 2, 3 and 5
- Smallest number with sum of digits as N and divisible by 10^N
- Find N digits number which is divisible by D
- 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
- Possible to make a divisible by 3 number using all digits in an array
- 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.