Given three different alphabets ‘a’, ‘b’ and ‘c’ with a certain rule that after every 2 seconds every ‘a’ changes to a ‘b’, after every 5 seconds every ‘b’ changes to one ‘c’ and after every 12 seconds every ‘c’ changes again into two ‘a’s.
Starting with one ‘a’, the task is to find the final count of a, b and c after given n seconds.
Input: n = 2
Output: a = 0, b = 1, c = 0
Initially a = 1, b = 0, c = 0
At n = 1, nothing will change
At n = 2, all a will change to b i.e. a = 0, b = 1, c = 0
Input: n = 72
Output: a = 64, b = 0, c = 0
Approach: It can be observed that the values of a, b and c will form a pattern after every 60 seconds (which is the LCM of 2, 5 and 12) as follows:
- At n = 60 -> a = 321, b = 0, c = 0
- At n = 120 -> a = 322, b = 0, c = 0
- At n = 180 -> a = 323, b = 0, c = 0 and so on.
If n is a multiple of 60 then calculate the result from the above observation else calculate the result for the multiple of 60 which is nearest to n say x and then update the result for the seconds from x + 1 to n.
Below is the implementation of the above approach:
a = 64, b = 0, c = 0
- Converting seconds into days, hours, minutes and seconds
- Find if the glass will be empty or not when the rate of drinking is given
- Program for converting hours into minutes and seconds
- Program to find the rate percentage from compound interest of consecutive years
- Count numbers < = N whose difference with the count of primes upto them is > = K
- Count subarrays such that remainder after dividing sum of elements by K gives count of elements
- Count pairs with given sum | Set 2
- Count Divisors of n in O(n^1/3)
- Count rotations of N which are Odd and Even
- Count pairs with Odd XOR
- Count numbers that don't contain 3
- Count of subarrays with sum at least K
- Count of all possible values of X such that A % X = B
- Count subarrays with Prime sum
- Count of pairs from 1 to a and 1 to b whose sum is divisible by N
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.