Math Algorithms Last Updated : 02 Apr, 2024 Comments Improve Suggest changes Like Article Like Report What are Mathematical Algorithms?Mathematical algorithm can be defined as an algorithm or procedure which is utilized to solve a mathematical problem, or mathematical problem which can be solved using DSA. In the field of DSA, mathematical algorithms refer to those algorithms which are generally used to solve problems related to the field of computer science. What are some use cases of Mathematical Algorithms?It is a very useful topic for solving problems of computer science and also has vast applications in competitive programming. Some of them are mentioned below: Problem-Solving: It is mostly used in solving complex mathematical ideas in mathematics and computer science.Competitive Programming: Algorithms like Sieve of Eratosthenes, Euclid algorithm, Binary exponentiation are some of the most common topics used in competitive programming.Recurrence relation: A lot of problems in DSA require the usage of recursion. Using the knowledge of mathematics several recurrence relations can be turned into mathematical formulae which makes solving the problem quite an easy task.Heavy calculation: Problems containing complex mathematical concepts and heavy calculations are easily done in comparatively less time using these algorithms instead of manual calculations.Statistics: Mathematical algorithms are also important for data processing, i.e., for converting raw data into useful information and also for analyzing them.Table of Content What are Mathematical Algorithms?What are some use cases of Mathematical Algorithms?Divisibility & Large Numbers:GCD and LCMSeriesNumber DigitsAlgebraNumber SystemPrime Numbers & Primality TestsPrime Factorization & DivisorsModular ArithmeticFactorialFibonacci NumbersCatalan NumbersnCr ComputationsSet TheorySieve AlgorithmsEuler Totient FunctionChinese Remainder TheoremSome Practice Problems Divisibility & Large Numbers:Check if a large number is divisible by 3 or notCheck if a large number is divisible by 4 or notCheck if a large number is divisible by 6 or notCheck divisibility by 7Check if a large number is divisible by 9 or notCheck if a large number is divisible by 11 or notDivisibility by 12 for a large numberCheck if a large number is divisible by 13 or notCheck if a large number is divisibility by 15Number is divisible by 29 or notGCD and LCM:LCM of arrayGCD of arrayBasic and Extended Euclidean algorithmsStein’s Algorithm for finding GCDGCD, LCM and Distributive PropertyCount number of pairs (A <= N, B <= N) such that gcd (A, B) is BProgram to find GCD of floating point numbersSeries with largest GCD and sum equals to nLargest Subset with GCD 1Summation of GCD of all the pairs up to NSeries:Juggler SequencePadovan SequenceAliquot SequenceMoser-de Bruijn SequenceStern-Brocot SequenceNewman-Conway SequenceSylvester’s sequenceRecaman’s sequenceSum of the sequence 2, 22, 222, ………Sum of series 1^2 + 3^2 + 5^2 + . . . + (2*n – 1)^2Sum of the series 0.6, 0.06, 0.006, 0.0006, …to n termsn-th term in series 2, 12, 36, 80, 150….Number Digits:Minimum digits to remove to make a number Perfect SquarePrint first k digits of 1/n where n is a positive integerCheck if a given number can be represented in given a no. of digits in any baseFind element using minimum segments in Seven Segment DisplayFind next greater number with same set of digitsCheck if a number is jumbled or notNumbers having difference with digit sum more than sTotal numbers with no repeated digits in a rangeK-th digit in ‘a’ raised to power ‘b’Algebra:Program to add two polynomialsMultiply two polynomialsFind number of solutions of a linear equation of n variablesCalculate the Discriminant ValueProgram for dot product and cross product of two vectorsIterated Logarithm log*(n)Program to find correlation coefficientProgram for Muller MethodNumber of non-negative integral solutions of a + b + c = nGenerate Pythagorean TripletsNumber System:Exponential notation of a decimal numberCheck if a number is power of k using base changing methodConvert a binary number to hexadecimal numberProgram for decimal to hexadecimal conversionConverting a Real Number (between 0 and 1) to Binary StringConvert from any base to decimal and vice versaDecimal to binary conversion without using arithmetic operatorsPrime Numbers & Primality Tests:Prime NumbersLeft-Truncatable PrimeMersenne PrimeSuper PrimeHardy-Ramanujan TheoremRosser’s TheoremFermat’s little theoremIntroduction to Primality Test and School MethodVantieghems Theorem for Primality TestAKS Primality TestLucas Primality TestPrime Factorization & Divisors:Prime factorsSmith NumbersSphenic NumberHoax Numberk-th prime factor of a given numberPollard’s Rho Algorithm for Prime FactorizationFinding power of prime number p in n!Find all divisors of a natural numberFind numbers with n-divisors in a given rangeModular Arithmetic:Modular Exponentiation (Power in Modular Arithmetic)Modular multiplicative inverseModular DivisionEuler’s criterion (Check if square root under modulo p exists)Find sum of modulo K of first N natural numberHow to compute mod of a big number?Exponential Squaring (Fast Modulo Multiplication)Trick for modular division ( (x1 * x2 …. xn) / b ) mod (m)Factorial:Program for factorial of a numberLegendre’s formula (Given p and n, find the largest x such that p^x divides n!)Count trailing zeroes in factorial of a numberFactorial of a large numberPrimorial of a numberFind maximum power of a number that divides a factorialLargest power of k in n! (factorial) where k may not be primeCheck if a number is a Krishnamurthy Number or notLast non-zero digit of a factorialCount digits in a factorial using LogarithmFibonacci Numbers:Fibonacci NumbersInteresting facts about Fibonacci numbersZeckendorf’s Theorem (Non-Neighbouring Fibonacci Representation)Finding nth Fibonacci Number using Golden RatioMatrix ExponentiationFibonacci CodingCassini’s IdentityTail Recursion for FibonacciCatalan Numbers:Catalan numbersApplications of Catalan NumbersDyck pathSuccinct Encoding of Binary TreeFind the number of valid parentheses expressions of given lengthnCr Computations:Binomial CoefficientIntroduction and Dynamic Programming solution to compute nCr%pProgram to calculate value of nCrRencontres Number (Counting partial derangements)Sum of squares of binomial coefficientsSpace and time efficient Binomial CoefficientHorner’s Method for Polynomial EvaluationSet Theory:Power SetMinimize the absolute difference of sum of two subsetsSum of all subsets of a set formed by first n natural numbersSum of average of all subsetsBell Numbers (Number of ways to Partition a Set)Sieve Algorithms:Sieve of EratosthenesSegmented SieveSieve of AtkinSieve of Sundaram to print all primes smaller than nSieve of Eratosthenes in 0(n) time complexityPrime Factorization using Sieve O(log n) for multiple queriesEuler Totient Function:Euler’s Totient FunctionOptimized Euler Totient Function for Multiple EvaluationsEuler’s Totient function for all numbers smaller than or equal to nPrimitive root of a prime number n modulo nEuler’s Four Square IdentityChinese Remainder Theorem:Introduction to Chinese Remainder TheoremImplementation of Chinese Remainder theorem (Inverse Modulo based implementation)Cyclic Redundancy Check and Modulo-2 DivisionUsing Chinese Remainder Theorem to Combine Modular equationsSome Practice Problems:Interquartile Range (IQR)Simulated AnnealingPseudo Random Number Generator (PRNG)Square root of a number using logFind ways an Integer can be expressed as sum of n-th power of unique natural numbersN-th root of a numberFast Fourier Transformation for poynomial multiplicationFind Harmonic mean using Arithmetic mean and Geometric meanDouble Base PalindromeProgram for Derivative of a PolynomialSgn value of a polynomialCheck if a number is a power of another numberProgram to evaluate simple expressionsMake a fair coin from a biased coinImplement *, – and / operations using only + arithmetic operatorQuick Links : Learn Data Structure and Algorithms | DSA TutorialPractrice Problems on Mathematical AlgorithmsQuizzes on Mathematical AlgorithmsVideos on Mathematical Algorithms Comment More infoAdvertise with us Next Article Math Algorithms H harendrakumar123 Follow Improve Article Tags : Algorithms Mathematical DSA Practice Tags : AlgorithmsMathematical Similar Reads Coding Challenge for Beginners | Coding Practice Challenges Start your coding journey with our Coding Challenge for Beginners! Hereâs a simple coding challenge suitable for beginners. This challenge involves writing a function in a programming language of your choice.These fun practice coding challenges will help you learn the basics of programming and impro 10 min read What is an Algebraic Formula? An algebraic formula is a mathematical expression that uses algebraic symbols to represent relationships and calculations. These formulas involve variables, constants, and arithmetic operations such as addition, subtraction, multiplication, division, and exponentiation. Algebraic formulas are fundam 5 min read Solving Expressions with Exponents Solving expressions with exponents involves understanding and applying rules such as the product of powers, quotient of powers, and power of a power. For instance, am à an = am+n and (am)n = amn. These properties simplify complex calculations. For example, (23)2 à 2â4 simplifies to 26â4 = 22 = 4. Un 4 min read Expressions And Equations Expression and Equations are two important concepts of algebra in mathematics. We need to learn about expressions and equations to solve different types of easy and complex problems in both mathematics and real-life applications. expression is a combination of numbers, variables, and operators while 6 min read Real Life Application of Simple Equations Simple equations are mathematical expressions that involve only basic arithmetic operations and typically involve one variable. Certain equations appear abstract and complicated, while others are straightforward but incredibly helpful in a variety of real-world situations. In this article, we're goi 4 min read Simplify and write (x2 - y2)(x-2 + y-2) using positive exponents Algebra is the branch of mathematics that deals with the study of various symbols which represent such quantities as do not have a constant value or quantity associated with them, instead they tend to vary or change over time with respect to some other factor. Such symbols are regarded as variables 5 min read Simplify (4m - 35)0/mn Algebra is the branch of mathematics that deals with the study of various symbols which represent such quantities as do not have a constant value or quantity associated with them, instead, they tend to vary or change over time with respect to some other factor. Such symbols are regarded as variables 4 min read Simplify [(2a3)/(3a5)3]3 using only positive exponents Algebra is the branch of mathematics that deals with the study of various symbols which represent such quantities as do not have a constant value or quantity associated with them, instead they tend to vary or change over time with respect to some other factor. Such symbols are regarded as variables 4 min read Find a simple expression for e{In x - 2ln y} Mathematics is not only about numbers but it is about dealing with different calculations involving numbers and variables. This is what basically known as Algebra. Algebra is defined as the representation of calculations involving mathematical expressions that consist of numbers, operators, and vari 5 min read Real-Life Applications of Mathematics Mathematics is the study of numbers, shapes, patterns, and how they relate to each other. It's not just about solving equations or doing calculations; it's a way of finding solutions and making sense of the world. From adding up grocery bills to designing video games or predicting the weather, math 6 min read Like