Found 7346 Articles for C++

Number of divisors of product of N numbers

Riya Kumari
Updated on 12-Jul-2023 12:26:49

224 Views

Divisor of a number is which divides it exactly without any remainders. In other words, a divisor of a number n is the one which results in n when multiplied by any other integer. It can also be called as a factor of a number. Dividend ÷ Divisor = Quotient. For example, if we divide 60 with 5 we will get 12 and vice versa therefore, 12 and 60 can be considered as divisors of 60. Number of Divisors of Product of N Numbers Given task is to find the number of divisors of the product of the given ... Read More

Number of divisors of a given number N which are divisible by K

Riya Kumari
Updated on 12-Jul-2023 12:24:02

160 Views

Finding the number of divisors of a given number N which is also divisible by K (any constant number) is a typical mathematical problem which requires lot of calculations. Here, K is usually a number which is less than or equal to square root of N. However, we can construct a C++ program by which counting such numbers will be an easier task. In this article, we will discuss different methods in C++ using which we can find solution to the above given problem. Input Output Scenarios If we consider the below scenario here we have N value as ... Read More

Convert a Binary String to Another by Flipping Prefixes a Minimum Number of Times

Prabhdeep Singh
Updated on 11-Jul-2023 16:24:09

148 Views

Prefixes are the substrings that start from the zeroth index and could be of any size from 1 to the length of the given string. We are given two binary string which means both strings contain only two different types of characters and we have to make the first string equal to the second one by flipping the prefix a minimum number of times. Also, it is given that the length of both of the given strings is equal. Input 1 string str1 = "01100" string str2 = "10101" Output 3 Explanation Only operation that we can perform ... Read More

Largest Roman Numeral Possible by Rearranging Characters of a Given String

Prabhdeep Singh
Updated on 11-Jul-2023 16:07:53

84 Views

The characters represent Roman numbers: 'I', 'V', 'X', 'L', 'C', 'D', and 'M'. We will be given a string that may contain another character also (all the characters will be uppercase English alphabets) and we have to find the largest Roman numerical number possible by altering the position of the characters of the given string, also if it is not possible to get one, then we will return invalid as the answer. Input 1 string str = “VICML” Output MCLVI Explanation In the given string we have M have the greater value followed by the C, and then all ... Read More

Karatsuba Algorithm for Fast Multiplication of Large Decimal Numbers Represented as Strings

Prabhdeep Singh
Updated on 11-Jul-2023 21:20:07

255 Views

We are not able to store the large decimal numbers in normal data types such as the int or even in long long, so we store them in the string. When we multiply two integers represented in the form of a string it takes a lot of time more specifically N*M where N is the size of the given string. In this article, we will implement Karatsuba Algorithm for the fast Multiplication of large decimal numbers represented as strings. Input string num1 = "34984" string num2 = "937488" Output 32797080192 Explanation We will see the algorithm for the ... Read More

Sort a string without altering the position of vowels

Prabhdeep Singh
Updated on 11-Jul-2023 09:02:29

379 Views

Sorting a string means we have to arrange a given string either in an ascending or descending order or any given order. In this problem given a string 'str' of size n. Our aim is to sort the given string without altering means without changing the position of vowels present in the string. Let's see examples with explanations below to understand the problem in a better way. Sample Examples Input 1 str = “abdecokfee” Output 1 abcedofkee Explanation Constant present in the string = bdckf Sort the constant string = bcdfk Merge the given string with the sorted instant string ... Read More

Maximum Number of 0s Placed Consecutively at the Start and End in any Rotation of a Binary String

Prabhdeep Singh
Updated on 11-Jul-2023 09:00:04

74 Views

Binary string means the string contains only two types of char either 1 or 0. It is known as base 2. In this problem, we have given a binary string str and also the size of the string 'n'. Our task is to find the maximum number of zeros places consecutively at the start and end of any rotation of a binary string. Let's see examples with explanations below to understand the problem in a better way. Sample Example Input 1 str = “101001, n = 6 Output 1 2 Explanation The string can be rotated in any of the ... Read More

C++ Program for Left Rotation and Right Rotation of a String

Prabhdeep Singh
Updated on 11-Jul-2023 08:56:40

668 Views

Rotation means we have to shift each character forward or backward direction. In the case of forward, the last character is forwarded to the index 0 also known as right rotation. In the case of backward first character at index 0 is backward to the last index also known as left rotation. In this problem, we have given a string of characters and integer d. Our task is to print the left rotated string or right rotated string by d integer. Only the permutation of the current string changes, not the length or frequency of the characters in the ... Read More

Check whether a very large number of the given form is a multiple of 3

Rinish Patidar
Updated on 21-Jun-2023 12:28:28

223 Views

The problem statement includes checking whether a K-sized very long positive integer is the multiple of 3 or not where each ith digit in the K-sized number where i>1 will be the sum of all the prefix digits modulo 10 from the left. We will be given two integers a0 and a1, where 1

Check whether a number is Emirpimes or not

Rinish Patidar
Updated on 21-Jun-2023 12:26:20

177 Views

The problem statement includes checking whether a number is Emirprimes or not, where the positive integer N will be the user input. An Emirpimes number is a semiprime number whose when digits are being reversed, gives a new number which too is a semiprime number. A semiprime number is a number which is the product of two prime numbers which can be either distinct or the same. In simple words, for a number N to be semiprime it should be of the form N=a*b, where a and b are prime numbers. They can be equal. In this problem, we will ... Read More

Advertisements