Given two integers A and B representing the time taken by two different Sand timers to get empty. The task is to find the count of flips of each timer till the instance at which both the Sand timers get empty at the same time.
Input: A = 30, B = 15
Output: 0 1
After 15 minutes: 15 0
Flip timer 2: 15 15
After another 15 minutes: 0 0
Input: A = 10, B = 8
Output: 3 4
Approach: Lowest Common Factor (LCM) of two number will determine the time at which both the Sand timers will get empty together.
LCM(A, B) = (A * B) / GCD(A, B)
Dividing the LCM by input will give the number of flips for each sand timer respectively.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum flip required to make Binary Matrix symmetric
- Horizontally Flip a Binary Matrix
- Counting numbers of n digits that are monotone
- Counting numbers whose difference from reverse is a product of k
- Rencontres Number (Counting partial derangements)
- Orbit counting theorem or Burnside's Lemma
- Counting Rock Samples | TCS Codevita 2020
- Counting Sort
- Secretary Problem (A Optimal Stopping Problem)
- Transportation Problem | Set 7 ( Degeneracy in Transportation Problem )
- The Knight's tour problem | Backtracking-1
- Josephus problem | Set 1 (A O(n) Solution)
- Hungarian Algorithm for Assignment Problem | Set 1 (Introduction)
- Frobenius coin problem
- The Lazy Caterer's Problem
- Josephus Problem Using Bit Magic
- Maths behind number of paths in matrix problem
- Number of stopping station problem
- Problem of 8 Neighbours of an element in a 2-D Matrix
- Fibonacci problem (Value of Fib(N)*Fib(N) - Fib(N-1) * Fib(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.