Programming Articles - Page 934 of 3363

Program to find expected growth of virus after time t in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:30:32

232 Views

Suppose there is a dangerous virus and that grows rapidly. The probability of number of virus cells growing by a factor x is 0.5 and also the probability of number of virus cells growing by a factor y is 0.5. Now if there was a single cell of virus at beginning, then calculate the expected number of virus cells after t time. If the answer is too large, then mod result by 10^9+7.So, if the input is like x = 2, y = 4, t = 1, then the output will be 3, because initially, the virus has only one ... Read More

Program to find number of solutions for given equations with four parameters in Python

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

277 Views

Suppose we have four numbers a, b, c and d and We have to find number of pairs (x, y) can be found such that that follows the equation: x^2 + y^2 = (x*a) + (y*b) where x in range [1, c] and y in range [1, d]So, if the input is like a = 2 b = 3 c = 2 d = 4, then the output will be 1 because one pair is (1, 1).To solve this, we will follow these steps −ans := 0for x in range 1 to c, dol := x*(x-a)det2 := b*b - 4*lif det2 is same as 0 and b is even and 1

Program to find last digit of the given sequence for given n in Python

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

243 Views

Suppose we have a value n. We have to find the last digit of sequence S. The equation of S is given below −$$\sum_{i=0\: 2^{^{i}}\leqslant n}^{\alpha } \sum_{j=0}^{n} 2^{2^{^{i}+2j}}$$So, if the input is like n = 2, then the output will be 6 because: here only i = 0 and i are valid, soS0 = 2^(2^0 + 0) + 2^(2^0 + 2) + 2^(2^0 + 4) = 42S1 = 2^(2^1 + 0) + 2^(2^1 + 2) + 2^(2^1 + 4) = 84 The sum is 42+84 = 126, so last digit is 6.To solve this, we will follow these steps −total:= 0temp := 1while temp

Program to find position of first event number of line l of a triangle of numbers in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:21:22

200 Views

Suppose we are generating a number triangle like below      1     1 1 1   1 2 3 2 1 1 3 6 7 6 3 1where in each row the elements are generated by adding three numbers on top of it. Now if we have a line number l. We have to find the position of first even number of that line. The position values are starting from 1.So, if the input is like l = 5, then the output will be 2          1       1  1 ... Read More

Program to find sum of the 2 power sum of all subarray sums of a given array in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:05:24

321 Views

Suppose we have a list A. We have taken all non-empty sublists of A as we know a list l with n elements has (2n - 1) non-empty sublist. Now for each sublist, he calculates sublist_sum (the sum of elements and denotes them by S1, S2, S3, ... , S(2N-1)). There is a special sum P such that P = 2S1 + 2S2 +2S3 .... + 2S(2N-1). We have to find P. If P is too large then return P mod (10^9 + 7).So, if the input is like A = [2, 2, 3], then the output will be The ... Read More

Program to check we can reach at position n by jumping or not in Python

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

186 Views

Suppose there is a number line from 1 to n. At first we are at position 0, jump one step to go 1, then jump two place to reach at position 3, then jump three position to reach at 6 and so on. We have to check whether maintaining this, we can reach at position n or not.So, if the input is like n = 21, then the output will be True, because 1+2+3+4+5+6 = 21To solve this, we will follow these steps −j:= (1 + square root of (1+8*n)) / 2if |j - int part of j|

Program to find sum of the costs of all simple undirected graphs with n nodes in Python

Arnab Chakraborty
Updated on 25-Oct-2021 06:59:57

356 Views

Suppose we have an undirected graph G with n nodes. Now consider the cost of a simple undirected graph is the sum of the costs of its nodes. And The cost of a node is D^k, where D is its degree. Now we have n and k values. We have to find the sum of the costs of all possible simple undirected graphs with n nodes. The result may be very large, so return the result modulo 1005060097.So, if the input is like n = 3 k = 2, then the output will be 36 because, there are eight simple ... Read More

Program to find number of elements in all permutation which are following given conditions in Python

Arnab Chakraborty
Updated on 25-Oct-2021 06:56:32

316 Views

Suppose we have a set A where all elements from 1 to n are present. And P(A) represents all permutations of elements present in A. We have to find number of elements in P(A) which satisfies the given conditionsFor all i in range [1, n], A[i] is not same as iThere exists a set of k indices {i1, i2, ... ik} such that A[ij] = ij+1 for all j < k and A[ik] = i1 (cyclic).So, if the input is like n = 3 k = 2, then the output will be 0 because -Consider the Array's are 1 indexed. ... Read More

Program to find number of ways we can arrange letters such that each prefix and suffix have more Bs than As in Python

Arnab Chakraborty
Updated on 25-Oct-2021 06:52:37

187 Views

Suppose we have a string with n number of A's and 2n number of B's. We have to find number of arrangements possible such that in each prefix and each suffix have number of B's greater than or equal to the number of A'sSo, if the input is like n = 2, then the output will be 4 because there are two A's and four B's, so possible arrangements are [BBAABB, BABABB, BBABAB, BABBAB].To solve this, we will follow these steps −Define a method solve, this will take nif n is same as 1, thenreturn 1if n is same as ... Read More

Program to find number of ways we can reach to the next floor using stairs in Python

Arnab Chakraborty
Updated on 25-Oct-2021 06:50:10

234 Views

Suppose there is a stair case with N steps. One can either go step by step, or at each step, one can take a jump of at most N steps. We have to find the number of ways in which we can go to the top floor. The N value may be large we are only interested in the first and the last K digits of number of ways.So, if the input is like N = 10 k = 2, then the output will be 63 because there are 10 steps, if there are S number of ways in which ... Read More

Advertisements