Programming Articles

Page 204 of 2544

Program to count number of trailing zeros of minimum number x which is divisible by all values from 1 to k in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 178 Views

Suppose we have a number k, now consider the smallest positive integer value x where all values from 1 to k divide evenly. In other words, consider the smallest value x where x is divisible by all numbers from 1 through k. We have to find the number of trailing zeroes in x.So, if the input is like k = 6, then the output will be 0, as the smallest x here is 60, 60 can be divided using 1, 2, 3, 4, 5 and 6. There is only one trailing zeroes in 60.To solve this, we will follow these steps −res := 0x := 1while x * 5

Read More

Count trailing zeros in factorial of a number in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 2K+ Views

Given an integer number as input. The goal is to find the number of trailing zeroes in the factorial calculated for that number. A factorial of a number N is a product of all numbers in the range [1, N].We know that we get a trailing zero only if the number is multiple of 10 or has a factor pair (2, 5). In all factorials of any number greater than 5, we have a number of 2s more than 5s in prime factorization of that number. Dividing a number by powers of 5 will give us the count of 5s ...

Read More

Fermat's little theorem in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 795 Views

Fermat’s little theorem −This theorem states that for any prime number p,           Ap - p is a multiple of p.This statement in modular arithmetic is denoted as,                  ap  ≡ a (mod p)If a is not divisible by p then,  ap - 1 ≡ 1 (mod p)In this problem, we are given two numbers a and p. Our task is to verify fermat’s little theorem on these values.We need to check if ap  ≡ a (mod p) or ap - 1 ≡ 1 (mod p)Holds true for the given values of a and p.Let’s take ...

Read More

Program to count number of configurations are there to fill area with dominos and trominos in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 143 Views

Suppose we have two shapes, Domino and Tromino. Dominos are 2 x 1 shape and Trominos are ‘L’ like shape. They can be rotated like below −If we have a number n, we have to find number of configurations to fill a 2 x n board with these two types of pieces. As we know in tiling, every square must be covered by a tile.So if the input is 3, then the output will be 5. So the arrangements can be [XYZ XXZ XYY XXY XYY] and [XYZ YYZ XZZ XYY XXY], here different letters are used for different tiles.To ...

Read More

How to create an empty data frame with fixed number of rows and without columns in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

To create an empty data frame with fixed number of rows but no columns, we can use data.frame function along with the matrix function. That means we need to create a matrix without any column using matrix and save it in a data frame using data.frame function as shown in the below examples.Example1> df1 df1Outputdata frame with 0 columns and 10 rows Example2> df2 df2Outputdata frame with 0 columns and 100 rows Example3> df3 df3Outputdata frame with 0 columns and 39 rows Example4> df4 df4Outputdata frame with 0 columns and 20 rows Example5> df5 df5Outputdata frame with 0 columns and ...

Read More

Fifth root of a number in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 1K+ Views

In this problem, we are given a number N. Our task is to find the floor value of the fifth root of a number.Fifth Root of a number is the number which when multiplied to itself 5 times returns the number.If N1/5 = a then, a*a*a*a*a = N.Let’s take an example to understand the problem, Input: N = 325Output: 3Explanation:  The fifth root of 325 is 3.179 whose floor value is 3.Solution Approach: A simple solution to the problem is traversing from 1 to n. And finding the number which when multiplied to itself five times gives the number.Here, the exact value cannot be found ...

Read More

Count pairs of parentheses sequences such that parentheses are balanced in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 974 Views

We are given a string containing the parentheses and the task is to calculate the count of pairs of parentheses sequences that can be formed such that the parentheses are balanced.Parentheses are said to be balanced when there are equal numbers of opening and closing brackets. The parentheses used once can’t be considered twice for forming the pair.Input − string paran[] = { ")()())", "(", ")(", ")(", ")" }Output − Count of pairs of parentheses sequences such that parentheses are balanced are: 1Explanation − we will take every set of string to calculate the count better. Lets take the first ...

Read More

Check if elements of Linked List are present in pair in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 356 Views

Suppose we have a singly linked list. We have to check whether each element in the given linked list is present in a pair, in other words all elements occur even no. of times.So, if the input is like list = [2, 5, 5, 2, 3, 3], then the output will be True.To solve this, we will follow these steps −xor_res := 0, current_node := head of linked listwhile current_node is not null, doxor_res := xor_res XOR value of current_nodecurrent_node := next of current_nodereturn False when xor_res is non-zero otherwise TrueExampleLet us see the following implementation to get better understanding ...

Read More

Count possible moves in the given direction in a grid in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 330 Views

We are two variables n and m representing a grid of size n x m and initial point x, y to start from.Also given pairs of steps/moves that can be taken to traverse inside the grid as moves ( (1, 1), (2, 2) ) etc. Each pair of moves represents the unit of steps taken in the x, y axis. The goal is to find the total steps that can be taken to traverse inside the grid within boundaries [1, n] X [1, m] If n is 5 and m is 4 and current position is 2, 2 and step ...

Read More

Program to count number of distinct characters of every substring of a string in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 386 Views

Suppose we have a lowercase string s, we have to find the sum of the count of characters that are distinct in every substring of s. If the answer is very large then return result mod 10^9+7.So, if the input is like s = "xxy", then the output will be 6, as the substrings and their counts are −"x" : 1"x" : 1"y" : 1"xx" : 0 (as "x" is not distinct)"xy" : 2"xxy" : 1 ("as "x" is not distinct)To solve this, we will follow these steps −m := 10^9 + 7prev_seen := a new empty mapans := 0Define ...

Read More
Showing 2031–2040 of 25,433 articles
« Prev 1 202 203 204 205 206 2544 Next »
Advertisements