Ravi Ranjan has Published 26 Articles

C++ Program to Perform Fermat Primality Test

Ravi Ranjan

Ravi Ranjan

Updated on 25-Apr-2025 11:22:19

870 Views

Fermat's Little theorem states that if 'p' is a prime number and 'a' is an integer that is not divisible by p, then a^(p-1) ≡ 1 modulo p or a^(p-1) mod p = 1. We will use Fermat's Little theorem to test whether the given number is a prime number ... Read More

C++ Program to Implement Euler Theorem

Ravi Ranjan

Ravi Ranjan

Updated on 23-Apr-2025 17:13:22

492 Views

Euler's theorem states that if two numbers (a and n), are co-prime i.e. gcd(a, n)=1, then 'a' raised to the power of Euler's totient function of n (a^φ(n)) is congruent to 1 modulo n i.e. a^φ(n) ≡ 1 (mod n). The Euler's Totient Function is denoted as φ(n) and represents ... Read More

C++ Program to Implement Fermat’s Little Theorem

Ravi Ranjan

Ravi Ranjan

Updated on 23-Apr-2025 17:07:46

815 Views

Fermat's Little Theorem states that if p is a prime number and a is an integer not divisible by p, then a^(p-1) is congruent to 1 modulo p. It can be represented as a(p-1) ≡ 1 (mod p). It can also be said that if any integer a is raised ... Read More

C++ Program to Implement Park-Miller Random Number Generation Algorithm

Ravi Ranjan

Ravi Ranjan

Updated on 23-Apr-2025 17:02:49

467 Views

The Park-Miller algorithm is a type of linear congruential generator (LCG) that is used to generate pseudo-random numbers. It is also called the minimal standard random number generator. The general formula of a random number generator (RNG) of this type is: X_{k+1} = g X(k) mod n where the modulus ... Read More

C++ Program to Implement Russian Peasant Multiplication

Ravi Ranjan

Ravi Ranjan

Updated on 22-Apr-2025 16:50:55

504 Views

The Russian Peasant multiplication is used to multiply two numbers without using the multiplication operator. It involves constant use of halving and doubling the numbers. In this article, we have two integers, our task is to find the product of these two integers by implementing russian peasant multiplication in C++. ... Read More

C++ Program to Generate Random Numbers Using Probability Distribution Function

Ravi Ranjan

Ravi Ranjan

Updated on 22-Apr-2025 11:38:55

2K+ Views

The probability density function (pdf) is a function that describes the relative likelihood for this random variable to take on a given value. It is also called as density of a continuous random variable. The probability of the random variable fall within a particular range of values is given by ... Read More

C++ Program to Generate Random Numbers Using Middle Square Method

Ravi Ranjan

Ravi Ranjan

Updated on 22-Apr-2025 11:38:27

1K+ Views

The middle-square method is one of the simplest methods of generating random numbers. This method will either begin repeatedly generating the same number or cycle to a previous number in the sequence and loop indefinitely. For a generator of n-digit random numbers, the period can be no longer than the ... Read More

C++ Program to Implement Interpolation Search Algorithm

Ravi Ranjan

Ravi Ranjan

Updated on 21-Apr-2025 14:40:31

1K+ Views

The interpolation search is an improved version of the binary search. The list is divided using the mid element in the binary search whereas the interpolation search algorithm tries to locate the exact position using the interpolation formula. For this algorithm to work properly, the data collection should be in ... Read More

C++ Program to Find kth Largest Element in a Sequence

Ravi Ranjan

Ravi Ranjan

Updated on 18-Apr-2025 16:55:33

296 Views

In this article, we have an unsorted array. Our task is to find the kth maximum element of that array using C++. Here is an example to understand the meaning of k. If k =2, you can say the second highest value, for k =3, the third highest value. The ... Read More

C++ Program to Implement Selection Sort

Ravi Ranjan

Ravi Ranjan

Updated on 17-Apr-2025 16:53:03

21K+ Views

The selection sort is an in-place comparison-based simple sorting algorithm. In the selection sort technique, the list is divided into two parts: sorted and unsorted. The minimum element from the unsorted part is selected and swapped with the element at the beginning of the list. Similarly, the next minimum value ... Read More

Advertisements