Find the Other Number When LCM and HCF are Given in C++

Arnab Chakraborty
Updated on 21-Oct-2019 08:09:36

112 Views

Suppose we have a number A, and LCM and GCD values, we have to find another number B. If A = 5, LCM is 25, HCF = 4, then another number will be 4. We know that −$$𝐴∗𝐵=𝐿𝐶𝑀∗𝐻𝐶𝐹$$$$𝐵= \frac{LCM*HCF}{A}$$Example Live Demo#include using namespace std; int anotherNumber(int A, int LCM, int GCD) {    return (LCM * GCD) / A; } int main() {    int A = 5, LCM = 25, GCD = 4;    cout

Find Surpasser Count of Each Element in Array in C++

Arnab Chakraborty
Updated on 21-Oct-2019 08:07:00

236 Views

Suppose one array A is given. We have to find a number of surpasser of each element in that array. The surpassers are greater elements which are present at the right side of the array of the current element. Suppose A = {2, 7, 5, 3, 0, 8, 1}, the surpassers are {4, 1, 1, 1, 2, 0, 0}, so 2 has 4 numbers at right side, which are greater than 4, and the same rule for others. The solution is very simple, two nested loops will be there, for each element, it will count surpassers, then store them into ... Read More

Find Nth Term of the Dragon Curve Sequence in C++

Arnab Chakraborty
Updated on 21-Oct-2019 08:04:02

244 Views

Here we will see a program, that can find nth term of the Dragon Curve sequence. The Dragon curve sequence is an infinite binary sequence. It starts with 1, and in each step, it alternatively adds 1s and 0s before and after each element of the previous term, to form the next term.Term 1 : 1Term 2 : 110Term 3 : 1101100Term 4 : 110110011100100We will start with 1, then add 1 and 0, alternatively after each element of the preceding term. When the new term obtained becomes the current term, then repeat the steps from 1 to n to ... Read More

Find LCM of Rational Number in C++

Arnab Chakraborty
Updated on 21-Oct-2019 07:59:16

170 Views

Here we will see how to find the LCM of Rational numbers. We have a list of rational numbers. Suppose the list is like {2/7, 3/14, 5/3}, then the LCM will be 30/1.To solve this problem, we have to calculate LCM of all numerators, then gcd of all denominators, then the LCM of rational numbers, will be like −$$LCM =\frac{LCM\:of\:all\:𝑛𝑢𝑚𝑒𝑟𝑎𝑡𝑜𝑟𝑠}{GCD\:of\:all\:𝑑𝑒𝑛𝑜𝑚𝑖𝑛𝑎𝑡𝑜𝑟𝑠}$$Example Live Demo#include #include #include using namespace std; int LCM(int a, int b) {    return (a * b) / (__gcd(a, b)); } int numeratorLCM(vector vect) {    int result = vect[0].first;    for (int i = 1; i ... Read More

Find if nCr is Divisible by Given Prime in C++

Arnab Chakraborty
Updated on 21-Oct-2019 07:52:50

188 Views

Suppose there are three variables N, R and P. The N and R are used to get the NCR and P is a prime. We have to find whether NCR is divisible by P. Suppose we have some numbers N = 7, R = 2 and P = 3, then 7C2 = 21, this is divisible by 3, so the output will be true.We know that NCR = N! / (R! * (N – R)! ). We will use Legendre Formula to largest power of P, which divides any N!, R! and (N – R)! in order to NCR to ... Read More

Find If a Point Lies Inside a Circle in C++

Arnab Chakraborty
Updated on 21-Oct-2019 07:46:31

3K+ Views

Suppose, one circle is given (the center coordinate and radius), another point is also given. We have to find whether the point is inside the circle or not. To solve it, we have to find the distance of the given point from circle center. If that distance is less or equal to the radius, then that is inside the circle, otherwise not.Example Live Demo#include #include using namespace std; bool isInsideCircle(int cx, int cy, int r, int x, int y) {    int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);    if ( dist

Install Lynis Linux Auditing Tool in CentOS

Lakshmi Srinivas
Updated on 21-Oct-2019 07:46:27

589 Views

Lynis is an open source and a powerful auditing tool for Unix-like operating systems. It scans system for protection knowledge, common approach know-how, any pre-installed software’s and to be had knowledge, configuration mistakes, safety disorders, consumer accounts without password, unsuitable file permissions, firewall auditing and so forth.Understanding LynisLinux performs individual test cases to secure your Linux system. To display test report, follow the below cases –Determine operating systemSearch for available tools and utilitiesCheck for Lynis updateRun tests from enabled pluginsRun security tests per categoryReport status of security scanDuring the test cases, all scanned details are stored in a log file ... Read More

Find HCF of Two Numbers Without Recursion or Euclidean Algorithm in C++

Arnab Chakraborty
Updated on 21-Oct-2019 07:43:18

734 Views

As we know, the HCF or GCD can be calculated easily using the Euclidean Algorithm. But here we will see how to generate GCD or HCF without using the Euclidean Algorithm, or any recursive algorithm. Suppose two numbers are present as 16 and 24. The GCD of these two is 8.Here the approach is simple. If the greater number of these two is divisible by the smaller one, then that is the HCF, otherwise starting from (smaller / 2) to 1, if the current element divides both the number, then that is the HCF.Example Live Demo#include using namespace std; int ... Read More

Find GCD of Factorial of Elements in C++

Arnab Chakraborty
Updated on 21-Oct-2019 07:39:53

409 Views

Suppose we have an array A, with N elements. We have to find the GCD of factorials of all elements of the array. Suppose the elements are {3, 4, 8, 6}, then the GCD of factorials is 6. Here we will see the trick. As the GCD of two numbers, is the greatest number, which divides both of the numbers, then GCD of factorial of two numbers is the value of factorial of the smallest number itself. So gcd of 3! and 5! is 3! = 6.Example Live Demo#include using namespace std; long fact(int n){    if(n arr[i])   ... Read More

Minimum Positive Integer Divisible by C and Not in Range in C++

Arnab Chakraborty
Updated on 21-Oct-2019 07:36:23

125 Views

Suppose we have three integers A, B, and C. We have to find one minimum integer X, such that X mod C = 0, and X is not in the range [A, B]. If the values of A, B and C are 5, 10 and 4 respectively, then the value of X will be 4. Let us see the steps to get the solution −Steps −If C is not in the range [A, B], then return C as a resultOtherwise get the first multiple of C, which is greater than B, then return that valueExample Live Demo#include using namespace std; ... Read More

Advertisements