In this article, we will learn how to find the product of all unique prime factors of a given number. For example, if the number is 12, its prime factors are 2 and 3, so the product would be 2 × 3 = 6. Problem statement − Given a number n, we need to find the product of all of its unique prime factors and return it. Example Input: num = 11 Output: Product is 11 Explanation: Here, the input number is 11 having only 1 prime factor and it is 11. And hence their product ... Read More
In this article, we will learn how to print a number series without using any loop. We'll use recursion to subtract and add values alternately until we return to the original number. Problem statement − Given two numbers N and K, subtract K from N until N becomes negative or zero, then start adding K until we reach the original number N again. Example Output N = 10, K = 4 Output: 10 6 2 -2 2 6 10 Algorithm The approach uses recursion with a flag to control the direction: ... Read More
In this article, we will compute the nth Fibonacci number using different approaches in Python. A Fibonacci number is defined by the recurrence relation given below − Fn = Fn-1 + Fn-2 With F0 = 0 and F1 = 1. The first few Fibonacci numbers are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... We can compute the Fibonacci numbers using recursion and dynamic programming methods. Let's explore both approaches with their implementations. Using Recursion Method The recursive approach directly implements the mathematical ... Read More
In this article, we will learn about calculating the nth Catalan number using different approaches in Python. Catalan numbers are a sequence of natural numbers that occur in various combinatorial problems. They are defined by the recursive formula: C₀ = 1 and Cₙ₊₁ = Σᵢ₌₀ⁿ CᵢCₙ₋ᵢ for n ≥ 0 The first few Catalan numbers for n = 0, 1, 2, 3, ... are 1, 1, 2, 5, 14, 42, 132, 429, ... Catalan numbers can be calculated using recursion or dynamic programming. Let's explore both implementations. Approach 1: Recursive Method The recursive approach directly implements the mathematical definition ? # A recursive solution def catalan(n): # Base case if n
In this article, we will learn how to check if a given number is a Fibonacci number using a mathematical property rather than generating the entire Fibonacci sequence. Problem Statement Given a number n, we need to determine whether n is a Fibonacci number or not. The Fibonacci sequence starts with 0 and 1, where each subsequent number is the sum of the previous two numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... Mathematical Property A number is Fibonacci if and only if (5*n² + 4) or (5*n² - 4) is ... Read More
In this article, we will learn how to find the Greatest Common Divisor (GCD) of more than two numbers or an array of numbers using Python. Problem statement − Given an array of numbers, we need to find the greatest common divisor of all elements. The GCD of multiple numbers can be calculated by repeatedly finding the GCD of pairs of numbers. We start with the first two numbers, find their GCD, then find the GCD of that result with the third number, and so on. Algorithm The approach involves: Implement a function to find ... Read More
In this article, we will learn about calculating the focal length of a spherical mirror using Python. We'll explore both concave and convex mirrors with their respective formulas. Problem Statement We are given the radius of curvature of a spherical mirror and need to find its focal length. The focal length is the distance between the center of curvature of the mirror to the principal focus. To determine the focal length of a spherical mirror, we need to know its radius of curvature − the distance from the vertex of the mirror to the center of curvature. ... Read More
In this article, we will learn how to find the vertex, focus, and directrix of a parabola given its equation in standard form y = ax² + bx + c. Problem Statement Given a parabola equation in the standard form y = ax² + bx + c, we need to find: Vertex: The point where the parabola changes direction Focus: A fixed point inside the parabola Directrix: A fixed line outside the parabola ... Read More
In this article, we will learn how to calculate the perimeter of a cylinder using Python. The perimeter represents the outline of the cylinder when viewed from the side. Understanding Cylinder Perimeter When we view a cylinder from the side, it appears as a rectangle. The perimeter is the total distance around this rectangular outline. diameter (d) height (h) ... Read More
We can create toast notifications for Windows 10 events using Python. This is very simple with the win10toast module. If you are familiar with Toast notifications in Android, then understanding toast notifications with Python is straightforward. We can generate notifications whenever an event occurs as a reminder. Installation Run the following command in command-line to install the win10toast module ? pip install win10toast If the module is successfully installed, you will get output similar to this ? Collecting win10toast Downloading https://files.pythonhosted.org/packages/d4/ba/95c0ea87d9bcad68b90d8cb130a313b939c88d8338a2fed7c11eaee972fe/win10toast-0.9-py2.py3-none-any.whl Collecting pypiwin32 (from win10toast) Installing collected packages: pypiwin32, win10toast Successfully installed ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance