Category Archives: Mathematical

Find pair with maximum GCD in an arrayJuly 23, 2017

We are given an array of positive integers. Find the pair in array with maximum GCD. Examples: Input : arr[] : { 1 2 3… Read More »

Inbuilt function for calculating LCM in C++July 22, 2017

Many times while we do programming, we need to calculate the Least Common Multiple (LCM) between two numbers. We have already discussed how to find… Read More »

Evil NumberJuly 18, 2017

An evil number is a non-negative number that has an even number of 1s in its binary expansion. (Binary Expansion – is representation of a… Read More »

Discrete Cosine Transform (Algorithm and Program)

Image Compression : Image is stored or transmitted with having pixel value. It can be compressed by reducing the value its every pixel contains. Image… Read More »

Number of times a number can be replaced by the sum of its digits until it only contains one digitJuly 16, 2017

Count the number of times a number can be replaced by the sum of its digits until it only contains one digit and number can… Read More »

Climb n-th stair with all jumps from 1 to n allowed (Three Different Approaches)July 14, 2017

A monkey is standing below at a staircase having N steps. Considering it can take a leap of 1 to N steps at a time,… Read More »

Print last k digits of a^b (a raised to power b)July 12, 2017

Given positive integers k, a and b we need to print last k digits of a^b ie.. pow(a, b). Input Constraint: k <= 9, a… Read More »

Josephus Problem Using Bit Magic

The Problem This problem is named after Flavius Josephus a Jewish historian who fought against the Romans. According to Josephus him and his group of… Read More »

Program to find root of an equations using secant method

The secant method is used to find the root of an equation f(x) = 0. It is started from two distinct estimates x1 and x2… Read More »

Count number of pairs (A <= N, B <= N) such that gcd (A , B) is B

Given a number n. We need find the number of ordered pairs of a and b such gcd(a, b) is b itself Examples: Input :… Read More »

Find the last digit of given seriesJuly 11, 2017

Given an integer n, find the last digit of this sequence, i.e. Summation of F(n) from i = 0 to 2i ≤ n, where F(n)… Read More »

Sum of all proper divisors of natural numbers in an array

Given an array of natural numbers count the sum of its proper divisors for every element in array. Input : int arr[] = {8, 13,… Read More »