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
- Program to find the rate percentage from compound interest of consecutive years
- Program for converting hours into minutes and seconds
- Count numbers < = N whose difference with the count of primes upto them is > = K
- Count rotations of N which are Odd and Even
- Count Divisors of n in O(n^1/3)
- Count of all possible values of X such that A % X = B
- Count pairs with Odd XOR
- Count pairs with given sum | Set 2
- Count numbers that don't contain 3
- Count Primes in Ranges
- Count of numbers having only 1 set bit in the range [0, n]
- Count of pairs from 1 to a and 1 to b whose sum is divisible by N
- Count of numbers satisfying m + sum(m) + sum(sum(m)) = N
- Count of all N digit numbers such that num + Rev(num) = 10^N - 1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.