Formula

Sum of 1st N Numbers :

( n * (n + 1) )/ 2

Count trailing zeroes in factorial of a number:

Divide the number by 5 until the number is > 0. Add all the quotient .

Modulo Property

(a+b+c) % x = (a%x + b%x + c%x) % x

(ab) mod p = ( (a mod p) (b mod p) ) mod p

Horner’s Method for Polynomial Evaluation

// Evaluate value of 2x3 - 6x2 + 2x - 1 for x = 3
Input: poly[] = {2, -6, 2, -1}, x = 3
Output: 5

// Evaluate value of 2x3 + 3x + 1 for x = 2
Input: poly[] = {2, 0, 3, 1}, x = 2
Output: 23

Horner’s method can be used to evaluate polynomial in O(n) time.Consider the example of 2x3 – 6x2 + 2x – 1. The polynomial can be evaluated as ((2x – 6)x + 2)x – 1.

Linear Diophantine Equations

Given three integers a, b, c representing a linear equation of the form: ax + by = c. To Determine if the equation has a solution such that x and y are both integral values.

Algorithm to determine if an equation has integral solution:

  • Find GCD of a and b

  • Check if c % GCD(a ,b) ==0

  • If yes then print Possible

  • Else print Not Possible

Common Divisors of Two Numbers

A better solution is to calculate the greatest common divisor (gcd) of given two numbers, and then count divisors of that gcd.

Check if a point lies inside circle

Distance between the points should be less than radius^2 (x - x1) * (x- x1) + (y-y1)*(y-y1) <= r*r

Last updated

Was this helpful?