- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

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

# Check whether product of digits at even places is divisible by sum of digits at odd place of a numbers in Python

Suppose we have a number n, we have to check whether the product of digits at even places of n is divisible by sum of digits at odd place of n or not. Places are started counting from right to left. Right most is at place 1.

So, if the input is like n = 59361, then the output will be True as (1*3*5) = (6+9).

To solve this, we will follow these steps −

- digit_count := digit count of given number n
- total := 0, prod := 1
- while n > 0, do
- if digit_count is even, then
- prod := prod * last digit of n

- otherwise,
- total := total + last digit of n

- n := quotient of (n / 10)
- digit_count := digit_count - 1

- if digit_count is even, then
- if prod is divisible by total, then
- return True

- return False

Let us see the following implementation to get better understanding −

## Example Code

from math import log10 def solve(n): digit_count = int(log10(n))+1 total = 0 prod = 1 while n > 0 : if digit_count % 2 == 0 : prod *= n % 10 else: total += n % 10 n = n // 10 digit_count -= 1 if prod % total == 0: return True return False n = 59361 print(solve(n))

## Input

59361

## Output

True

- Related Questions & Answers
- Check whether product of digits at even places of a number is divisible by K in Python
- Check whether sum of digits at odd places of a number is divisible by K 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++
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers - JavaScript
- Check whether product of 'n' numbers is even or odd in Python
- Finding all the n digit numbers that have sum of even and odd positioned digits divisible by given numbers - JavaScript
- Count Numbers in Range with difference between Sum of digits at even and odd positions as Prime in C++
- Even numbers at even index and odd numbers at odd index in C++
- C Program to check if a number is divisible by sum of its digits
- Count of all even numbers in the range [L, R] whose sum of digits is divisible by 3 in C++
- Check if product of first N natural numbers is divisible by their sum in Python
- Difference between sums of odd and even digits.
- Sum of individual even and odd digits in a string number using JavaScript

Advertisements