Found 7197 Articles for C++

Power of a prime number r in n! in C++

sudhir sharma
Updated on 17-Apr-2020 06:49:39

221 Views

In this problem, we are given two integer n and r. Our task is to find the power of the given prime number r in the factorial of the number n.Let’s take an example to understand the problemInput − n = 6 r = 2Output − 4Explanation −Factorial n, 6! = 6*5*4*3*2*1 = 720 720 = 24 * 32 * 5, power of 2 is 4To solve this problem, a simple solution would be directly finding the factorial and then finding the power of the prime number. But this is not the best solution.Another efficient solution is using a formula, ... Read More

Power Set in Lexicographic order in C++

sudhir sharma
Updated on 17-Apr-2020 06:46:51

758 Views

In this problem, we are given string str. Our task is to print the power set of this string’s elements in lexicographical order.Power Set − The power set of a set is the set of all subsets of the set. Denoted by P(S) where s is the set.Example −S = {1, 2, 3} ; p(S) = {{}, {1}, {1, 2}, {1, 3}, {2}, {2, 3}, {3}, {1, 2, 3}}In this problem, we will treat the string as a set. So, its characters will be the elements of the set.Let’s take an example to understand the problemInput − str = “xyz”Output ... Read More

Powers of 2 to required sum in C++

sudhir sharma
Updated on 17-Apr-2020 06:43:33

674 Views

In this problem, we are given an integer N. Our task is to print the number which when raised to the power of 2 gives the number.Let’s take an example to understand the problemInput − 17Output − 0, 4Explanation − 17 = 24 + 20 = 16 + 1To solve this problem, we will divide the number with 2 recursively. By this method, every number can be represented as a power of 2. This method is used to convert the number to its binary equivalent.ExampleThe program to show the implementation of our solution Live Demo#include using namespace std; void sumPower(long ... Read More

Powers of two and subsequences in C++

sudhir sharma
Updated on 17-Apr-2020 06:41:39

208 Views

In this problem, we are given an array of N integers. Our task is to find the count of subsequences that can be formed such that if their elements are multiplied, they result in a number which is a power of two.Let’s take an example to understand the problem, Input − arr = [2, 5, 4]Output − 3Explanation − subsequences [2], [4] and [2, 4] give the desired result.To solve this problem, we need to understand the logic of power.Only those numbers with are powers of 2 will multiply to give the desired result. So, we have to consider only ... Read More

map::at() in C++ STL

Sunidhi Bansal
Updated on 15-Apr-2020 12:58:18

424 Views

In this article we will be discussing the working, syntax and examples of map::at() function in C++ STL.What is a Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination of key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in the map container are accessed by its unique keys.What is a map::at()?map::at() function is an inbuilt function in C++ STL, which is defined in  header file. at() is used to access a ... Read More

map::size() in C++ STL

Sunidhi Bansal
Updated on 15-Apr-2020 12:56:27

8K+ Views

In this article we will be discussing the working, syntax and examples of map::size() function in C++ STL.What is a Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination of key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in the map container are accessed by its unique keys.What is a map::size()?map::size() function is an inbuilt function in C++ STL, which is defined in  header file. size() is used to check the ... Read More

map::empty() in C++ STL

Sunidhi Bansal
Updated on 15-Apr-2020 12:51:44

525 Views

In this article we will be discussing the working, syntax and examples of map::empty() function in C++ STL.What is a Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination of key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in the map container are accessed by its unique keys.What is a map::empty()?map::empty() function is an inbuilt function in C++ STL, which is defined in  header file. empty() is used to check whether ... Read More

map::begin() and end() in C++ STL

Sunidhi Bansal
Updated on 15-Apr-2020 12:48:05

812 Views

In this article we will be discussing the working, syntax and examples of map::begin() and map::end() functions in C++ STL.What is a Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination of key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in the map container are accessed by its unique keys.What is a map::begin()?map::begin() function is an inbuilt function in C++ STL, which is defined in  header file. begin() is used to ... Read More

map::at() and map::swap() in C++ STL

Sunidhi Bansal
Updated on 15-Apr-2020 12:45:24

578 Views

In this article we will be discussing the working, syntax and examples of map::at() and map::swap() functions in C++ STL.What is a Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination of key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in the map container are accessed by its unique keys.What is a map::at()?map::at() function is an inbuilt function in C++ STL, which is defined in  header file. at() is used to ... Read More

map operator= in C++ STL

Sunidhi Bansal
Updated on 15-Apr-2020 12:42:03

207 Views

In this article we will be discussing the working, syntax and example of map equal ‘=’ operator in C++ STL.What is a Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination of key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in the map container are accessed by its unique keys.What is a map equal to ‘=’ operator?map::operator= is an equal to operator. This operator is used to copy the elements from ... Read More

Advertisements