- Related Questions & Answers
- Check whether product of digits at even places of a number is divisible by K in Python
- Check whether product of digits at even places is divisible by sum of digits at odd place of a numbers in Python
- Check if product of digits of a number at even and odd places is equal in Python
- Find the sum of digits of a number at even and odd places in C++
- Primality test for the sum of digits at odd places of a number in C++
- C Program to check if a number is divisible by sum of its digits
- C Program to check if a number is divisible by any of its digits
- Find number of substrings of length k whose sum of ASCII value of characters is divisible by k in C++
- Check whether sum of digit of a number is Palindrome - JavaScript
- Check if N is divisible by a number which is composed of the digits from the set {A, B} in Python
- Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Maximize the number of sum pairs which are divisible by K in C++
- Check if any permutation of a large number is divisible by 8 in Python
- Check whether the sum of absolute difference of adjacent digits is Prime or not in Python
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers - JavaScript

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have a number n and another number k, we have to check whether the sum of digits of n at it's odd places (from right side to left side) is divisible by k or not.

So, if the input is like n = 2416 k = 5, then the output will be True as sum of odd placed numbers from right to left is 4 + 6 = 10. Which is divisible by 5.

To solve this, we will follow these steps −

- total := 0, pos := 1
- while n > 0 , do
- if pos is odd, then
- total := total + (n mod 10)

- n := quotient of (n / 10)
- pos := pos + 1

- if pos is odd, then
- if total is divisible by k, then
- return True

- return False

Let us see the following implementation to get better understanding −

def solve(n, k): total = 0 pos = 1 while n > 0: if pos % 2 == 1: total += n % 10 n = n // 10 pos += 1 if total % k == 0: return True return False n = 2416 k = 5 print(solve(n, k))

2416, 5

True

Advertisements