Category: Python Programming Examples

python tutorials and learn python

Python Program for Difference between sums of odd and even digits

Python Program for Difference between sums of odd and even digits Given a long integer, we need to find if the difference between sum of odd digits and sum of even digits is 0 or not. The indexes start from zero (0 index is for leftmost digit). Examples: Input : 1212112 Output : Yes Explanation:-…

Python Program for Find minimum sum of factors of number

Python Program for Find minimum sum of factors of number Given a number, find minimum sum of its factors. Examples: Input : 12 Output : 7 Explanation: Following are different ways to factorize 12 and sum of factors in different ways. 12 = 12 * 1 = 12 + 1 = 13 12 = 2…

Python Program for Check if count of divisors is even or odd

Python Program for Check if count of divisors is even or odd Given a number “n”, find its total number of divisors are even or odd. Examples : Input : n = 10 Output : Even Input: n = 100 Output: Odd Input: n = 125 Output: Even A naive approach would be to find…

Python Program for GCD of more than two (or array) numbers

Python Program for GCD of more than two (or array) numbers The GCD of three or more numbers equals the product of the prime factors common to all the numbers, but it can also be calculated by repeatedly taking the GCDs of pairs of numbers. gcd(a, b, c) = gcd(a, gcd(b, c)) = gcd(gcd(a, b),…

Python Program for Maximum height when coins are arranged in a triangle

Python Program for Maximum height when coins are arranged in a triangle We have N coins which need to arrange in form of a triangle, i.e. first row will have 1 coin, second row will have 2 coins and so on, we need to tell maximum height which we can achieve by using these N…

Python Program for Common Divisors of Two Numbers

Python Program for Common Divisors of Two Numbers Given two integer numbers, the task is to find count of all common divisors of given numbers? Input : a = 12, b = 24 Output: 6 // all common divisors are 1, 2, 3, // 4, 6 and 12 Input : a = 3, b =…

Python Program for Number of elements with odd factors in given range

Python Program for Number of elements with odd factors in given range Given a range [n,m], find the number of elements that have odd number of factors in the given range (n and m inclusive). Examples: Input : n = 5, m = 100 Output : 8 The numbers with odd factors are 9, 16,…

Python Program for Extended Euclidean algorithms

Python Program for Extended Euclidean algorithms # Python program to demonstrate working of extended # Euclidean Algorithm   # function for extended Euclidean Algorithm def gcdExtended(a, b, x, y):     # Base Case     if a == 0 :          x = 0         y = 1         return b               x1 = 1     y1 = 1 # To store…