Programming Articles - Page 933 of 3363

Program to find coefficients of linear equations that has only one solution in Python

Arnab Chakraborty
Updated on 25-Oct-2021 08:11:57

535 Views

Suppose we have a value n, we have to find the number of pairs (a, b) [a < b], that exist such that the equation a*x + b*y = n, has at least one solution.So, if the input is like n = 4, then the output will be 2 because the valid pairs are (1, 2) and (1, 3).To solve this, we will follow these steps −Define a function divisors_gen() . This will take ndivs := a list of lists of size n+1. And each inner list is holding 1divs[0] := a list with only one element 0for i in ... Read More

Program to find number m such that it has n number of 0s at end in Python

Arnab Chakraborty
Updated on 25-Oct-2021 08:08:24

152 Views

Suppose we have a number n. We have to find smallest number m, such that factorial of m has at least n number of 0s.So, if the input is like n = 2, then the output will be 10 because 10! = 3628800 and 9! = 362880, minimum number with 2 zeros is 10.To solve this, we will follow these steps −Define a function count_fives() . This will take ncnt := 0while n > 0, don := floor of (n / 5)cnt := cnt + nreturn cntFrom the main method, do the following −left := 1right := 5^24while right - ... Read More

Program to find hoe many children will get candies while distributing them maintaining the rules in Python

Arnab Chakraborty
Updated on 25-Oct-2021 08:05:08

339 Views

Suppose we have k number of candies. We have to distribute them among children. Now there are some rulesith child will get i^2 number of candiesany children at index i will not get any candy until all children from index 1 to i-i are servedIf ith children does not get i^2 number of candies, then that is not a valid serve.So, if the input is like k = 20, then the output will be 3 because, first one will get 1, second one will get 2^2 = 4, third one will get 3^2 = 9, but fourth one needs 4^2 ... Read More

Program to find remainder after dividing n number of 1s by m in Python

Arnab Chakraborty
Updated on 25-Oct-2021 08:02:07

503 Views

Suppose we have two numbers n and m. We have to find the remainder after dividing n number of 1s by m.So, if the input is like n = 4 m = 27, then the output will be 4, because 1111 mod 27 = 4.To solve this, we will follow these steps −Define a function util() . This will take x, n, my := 1while n > 0, doif n is odd, theny := (y * x) mod mx := (x * x) mod mn := floor of n/2return yFrom the main method return floor of (util(10, n, 9 * ... Read More

Program to find number of pairs from N natural numbers whose sum values are divisible by k in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:59:43

302 Views

Suppose we have a number n and another value k, consider we have an array A with first N natural numbers, we have to find the total number of pairs of elements A[i] and A[j] from A, such that, i < j and their sum is divisible by k.So, if the input is like n = 10 k = 4, then the output will be 10 because there are 10 pairs whose sum is divisible by 4. [(1, 3), (1, 7), (2, 6), (2, 10), (3, 5), (3, 9), (4, 8), (5, 7), (6, 10), (7, 9)]To solve this, we ... Read More

Program to find common fraction between min and max using given constraint in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:55:26

403 Views

Suppose we have two long integer values maximum and minimum. We have to find a common fraction n/d such that min

Program to find probability that any proper divisor of n would be an even perfect square number in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:50:08

147 Views

Suppose we have a number n, we have to find out the probability that any proper divisor of n would be an even perfect square.So, if the input is like n = 36, then the output will be 1/8 because there are eight proper divisors of 36, these are {1, 2, 3, 4, 6, 9, 12, 18} and among them only one number (4) is perfect square and even.To solve this, we will follow these steps −if n mod 4 is not same as 0, thenreturn 0otherwise, nc := n, ptr := 2l := a new listwhile ptr 0, ... Read More

Program to find value of find(x, y) is even or odd in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:43:58

292 Views

Suppose we have an array nums. We also have another pair (x, y), we need to find whether the value find(x, y) is Odd or Even. The find() is as followsfind(x, y) = 1 if x > yfind(x, y) = nums[x]^find(x+1, y) otherwiseSo, if the input is like nums = [3, 2, 7] (x, y) = 1, 2, then the output will be even, because −find(1, 2) = nums[1]^find(2, 3)find(2, 2) = nums[2]^find(3, 2)find(3, 2) = 1, so find(2, 2) = 7, and find(1, 2) = 2^7 = 128, this is evenTo solve this, we will follow these steps −even ... Read More

Program find number of subsets of colorful vertices that meets given conditions in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:41:12

161 Views

Suppose we have an array colors, representing colors for one regular n-gon. Here each vertex of this n-gon was randomly colored with one of n different colors present in the given array. We have to find the number of special subsets of polygon vertices, such that these subsets meet these conditions −The size of subset must be at least two.If we remove vertices which are present in the subset, from the polygon (the adjacent edges of those vertices will also get removed), then the remaining vertices and edges form some continuous paths.None of those paths should contain two vertices of ... Read More

Program to find number of expected moves required to win Lotus and Caterpillar game in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:36:43

199 Views

Suppose we have a grid with n rows and m columns. Amal and Bimal are playing a game on that grid. The game rule is like below −Amal places white lotus tile somewhere at the top row and Bimal places a caterpillar tile somewhere on the bottom row. Amal starts the game and they are playing alternatively. Amal can move his tile to any of the 8 adjacent cells inside the grid of the current cell, but Bimal's caterpillar tile can only move left or right inside the grid, or stay at the same position. Amal's goal is to catch ... Read More

Advertisements