Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Python Articles
Page 697 of 855
Python Program for Smallest K digit number divisible by X
In this article, we will learn how to find the smallest K-digit number that is divisible by a given number X. This is a common mathematical programming problem that involves understanding number ranges and divisibility concepts. Problem Statement Given two integers K and X, we need to find the smallest K-digit number that is divisible by X. For example: K=3, X=7: Find smallest 3-digit number divisible by 7 K=4, X=13: Find smallest 4-digit number divisible by 13 Approach The solution follows these steps: Calculate MIN: The smallest K-digit number is 10^(K-1). ...
Read MoreLinear Search in Python Program
Linear search is a simple searching algorithm that checks each element in a list sequentially until the target element is found or the entire list is traversed. It's the most straightforward search method but not the most efficient for large datasets. Algorithm Start from the leftmost element of the given array and compare the target element x with each element one by one If x matches with any element, return its index position If x doesn't match with any elements in the array, return -1 or "element not found" Visual Representation Here's how linear ...
Read MoreInsertion Sort in Python Program
In this article, we will learn about the implementation of Insertion Sort in Python. Insertion sort is a simple sorting algorithm that builds the final sorted array one item at a time, similar to how you might sort playing cards in your hands. Algorithm Iterate over the input elements by growing the sorted array at each iteration. Compare the current element with the largest value available in the sorted array. If the current element is greater, then it leaves the element in its place and moves on to the next element else it finds its correct position ...
Read MoreFinding the vertex, focus and directrix of a parabola in Python Program
In this article, we will learn about finding the vertex, focus and directrix of a parabola using Python. A parabola is a U-shaped curve that can be represented by the standard form equation y = ax² + bx + c. Understanding Parabola Components ...
Read MorePython Program for Find sum of Series with the n-th term as n^2 – (n-1)^2
In this article, we will learn how to find the sum of a series where the n-th term is defined as n² - (n-1)². We'll explore the mathematical pattern and implement an efficient solution. Problem Statement We are given an integer input n and we need to find the sum of all n terms where the n-th term in the series is expressed as − Tn = n² - (n-1)² Understanding the Pattern Let's first understand what this series looks like by calculating the first few terms − # Calculate first ...
Read MorePython Program for Find sum of odd factors of a number
In this article, we will learn how to find the sum of odd factors of a number. We need to identify all factors that are odd and calculate their sum. Problem Statement Given a number n, find the sum of all its odd factors. For example, if n = 12, the factors are [1, 2, 3, 4, 6, 12], and the odd factors are [1, 3], so the sum is 4. Approach To find odd factors efficiently, we first eliminate all even factors by dividing the number by 2 repeatedly. Then we find all remaining odd ...
Read MorePython Program for Find reminder of array multiplication divided by n
In this article, we will learn about finding the remainder when the product of all array elements is divided by a given number n. This approach uses modular arithmetic properties to avoid overflow issues. Problem Statement Given an array of numbers and a divisor n, we need to find the remainder after multiplying all array elements and dividing by n. Approach We use the distributive property of modular arithmetic to compute the result efficiently − First, compute the remainder of each element like arr[i] % n. Then multiply this remainder ...
Read MorePython Program for Find minimum sum of factors of number
In this article, we will learn how to find the minimum sum of factors of a given number. The key insight is that the minimum sum is achieved by using the sum of prime factors of the number. Problem Statement Given a number, find the minimum sum of factors that can multiply to give the original number. For example, the number 12 can be expressed as: 12 = 12 (sum = 12) 12 = 6 × 2 (sum = 8) 12 = 4 × 3 (sum = 7) 12 = 3 × 2 × 2 (sum ...
Read MorePython Program for Fibonacci numbers
The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. In this article, we will learn different approaches to compute the nth Fibonacci number in Python. Problem statement − Our task is to compute the nth Fibonacci number. The sequence Fn of Fibonacci numbers is given by the recurrence relation: Fn = Fn-1 + Fn-2 with seed values: F0 = 0 and F1 = 1 We have two main approaches to solve this problem: Recursive approach Dynamic programming approach Using Recursive ...
Read MorePython Program for Difference between sums of odd and even digits
In this article, we will learn how to find the difference between the sum of odd digits and sum of even digits in a number, and check if this difference equals zero. Problem Statement − Given an integer, we need to calculate if the difference between the sum of odd digits and sum of even digits is 0 or not. Method 1: Brute Force Approach The straightforward approach calculates the sum of all even and odd digits separately, then finds their difference ? def difference_odd_even_digits(n): n = abs(n) # Handle ...
Read More