Mathematical AlgorithmsLast Updated : 26 Sep, 2023ReadDiscussCoursesDSA for BeginnersLearn more about Mathematical Algorithms in DSA Self Paced CoursePractice Problems on Mathematical AlgorithmsWhat 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:1. Problem-Solving: It is mostly used in solving complex mathematical ideas in mathematics and computer science.2. Competitive Programming: Algorithms like Sieve of Eratosthenes, Euclid algorithm, Binary exponentiation are some of the most common topics used in competitive programming.3. 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.4. Heavy calculation: Problems containing complex mathematical concepts and heavy calculations are easily done in comparatively less time using these algorithms instead of manual calculations.5. Statistics: Mathematical algorithms are also important for data processing, i.e., for converting raw data into useful information and also for analyzing them.Topics:Divisibility & Large NumbersGCD 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 AlgorithmsIf you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.