Server Side Programming Articles - Page 1898 of 2646

Prime Factor in C++ Program

sudhir sharma
Updated on 03-Feb-2020 11:07:13

12K+ Views

Prime Factor is a prime number which is the factor of the given number.Factor of a number are the numbers that are multiplied to get the given number.Prime Factorisation is the process of recursively dividing the number with its prime factors to find all the prime factors of the number.Example : N = 120 Prime factors = 2 5 3 Factorization : 2 * 2 * 2 * 3 * 5Some points to remember about prime factors of a numberSet of prime factors of a number is unique.Factorization is important in many mathematical calculations like divisibility, finding common denominators, etc.It’s ... Read More

Prime factors of a big number in C++

sudhir sharma
Updated on 03-Feb-2020 11:04:19

1K+ Views

In this problem, we are given an integer N

Find Minimum in Rotated Sorted Array in C++

Ravi Ranjan
Updated on 09-Jun-2025 19:15:17

446 Views

A sorted and rotated array is an array that is sorted in ascending or descending order and then rotated either left or right by a specific number of elements. There should exist exactly one pivot point around which the array is rotated. In this article, our task is to find the minimum element in the given sorted and rotated array. We will use the following two approaches mentioned below: Using Linear Search Using Binary Search Example Here is an example of searching the ... Read More

Prime factors of LCM of array elements in C++

sudhir sharma
Updated on 03-Feb-2020 11:01:51

223 Views

In this problem, we are given an array within the range 1

Maximum Product Subarray in Python

Arnab Chakraborty
Updated on 04-May-2020 08:51:03

1K+ Views

Suppose we have an integer array called nums, we have to find the contiguous subarray within an array (containing at least one number) which has the largest product. So if the array is [2, 3, -2, 4], the output will be 6, as contiguous subarray [2, 3] has max product.To solve this, we will follow these steps −max_list := list of size nums, and fill with 0min_list := list of size nums, and fill with 0max_list[0] := nums[0] and min_list[0] := nums[0]for i in range 1 to length of numsmax_list[i] = max of max_list[i - 1]*nums[i], min_list[i - 1]*nums[i] and ... Read More

Prime Number of Set Bits in Binary Representation in C++

sudhir sharma
Updated on 03-Feb-2020 10:57:50

282 Views

In this problem, we are given two integers L and R. Our task to print the total numbers that have set bits counting to a prime number that is in between L to R.Let’s take an example to understand the problemInput: L = 7, R = 12 Output: 6 Explanation: 7 -> 111 , set bits = 2, prime number. 8 -> 1000 , set bits = 1, not prime number. 9 -> 1001 , set bits = 2, prime number 10 -> 1010 , set bits = 2, prime number 11 -> 1011, set bits = 3, prime number ... Read More

Insertion Sort List C++

Arnab Chakraborty
Updated on 03-Feb-2020 10:56:31

499 Views

Suppose we have a linked list, we have to perform the insertion sort on this list. So if the list is like [9, 45, 23, 71, 80, 55], sorted list is [9, 23, 45, 55, 71, 80].To solve this, we will follow these steps −dummy := new Node with some random valuenode := given listwhile node is not null, newNode = next of node, dummyHead := next of dummy, prevDummyHead := dummywhile true −if dummyHead is not present, value of dummyHead > value of nodenext of node := dummyHeadnext of prevDummyHead := nodebreak the loopprevDummyHead := dymmyHead, and dummyHead = ... Read More

Binary Tree Preorder Traversal in Python

Arnab Chakraborty
Updated on 04-May-2020 06:38:33

1K+ Views

Suppose we have a binary tree. We have to return the preorder traversal of that tree. So if the tree is like −Then the preorder traversal will be: [3, 9, 20, 15, 7]To solve this, we will follow these steps −make empty lists called res and st.node := rootwhile node or st is not emptywhile node is not null, theninsert val of node into res, insert node into st and set node := left of nodetemp := last element of st, and delete last element of stif right of temp is available, thennode := right of tempreturn resLet us see ... Read More

Prime numbers after prime P with sum S in C++

sudhir sharma
Updated on 03-Feb-2020 10:53:23

391 Views

In this problem, we are given three numbers, sum S, prime P, and N. Our task is to find all N prime numbers greater than P whose sum is equal to S.Let’s take an example to understand our problemInput: N = 2, P = 5, S = 18 Output: 7 11 Explanation: Prime numbers greater than 5 : 7 11 13 Sum = 7 + 11 = 18To solve this problem, we have to find all prime numbers between P and S. And then find N prime numbers which sum up to S. For this we will use backtracking.Program to ... Read More

Linked List Cycle II in C++

Arnab Chakraborty
Updated on 04-May-2020 06:37:34

391 Views

Consider we have a linked list, and we have to check whether there is any cycle or not. To represent the cycle in the given linked list, we will use one integer pointer called pos. This pos represents a position in the linked list where tail is connected. So if pos is -1, then there is no cycle present in the linked list. For example, the linked list is like [5, 3, 2, 0, -4, 7], and pos = 1. So there is a cycle, and tail is connected to the second node. The constraint is that we cannot modify ... Read More

Advertisements