Given the total number of Legs and Head of Rabbits and Pigeons. The task is to calculate the number of Rabbits and Pigeons.
Input: Heads = 200, Legs = 540 Output: Rabbits = 70, Pigeons = 130 Input: Heads = 100, Legs = 300 Output: Rabbits = 50, Pigeons = 50
Let the total no. of Heads = 200 and Legs = 540.
Let the number of Head and Legs of Rabbits = X and that of Pigeons = Y.
X + Y = 200 ..equation 1 (no. of the heads of a rabbit and a pigeon = total no. of heads)
(As both of them has 1 head)
4X + 2Y = 540 …equation 2 (no. of the legs of the rabbit and a pigeon = total no. of legs)
(Rabbit have 4 legs and pigeons have 2 legs)
Now, solving equation 1 and 2 we get,
4X = 540 – 2Y
4X = 540 – 2 * (200 – X)
4X = 540 – 400 + 2X
2X = 140 => X = 70
X = 70 and Y = 130.
hence, Rabbits = 70 and Pigeons = 130
Below is the implementation of the above approach:
Rabbits = 50 Pigeons = 50
- Number of sequences which has HEAD at alternate positions to the right of the first HEAD
- Count number of triplets with product equal to given number with duplicates allowed
- Count number of trailing zeros in Binary representation of a number using Bitset
- Find count of digits in a number that divide the number
- Count number of digits after decimal on dividing a number
- Count the number of operations required to reduce the given number
- Count number of ways to divide a number in 4 parts
- Count number of subsets of a set with GCD equal to a given number
- Count the number of occurrences of a particular digit in a number
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Count of cells in a matrix which give a Fibonacci number when the count of adjacent cells is added
- Count number of triplets (a, b, c) such that a^2 + b^2 = c^2 and 1 <= a <= b <= c <= n
- Count Hexadecimal Number
- Count number of ways to get Odd Sum
- Count number of pairs (A <= N, B <= N) such that gcd (A , B) is B
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.