Sand Timer Flip Counting Problem | Java implementation of the approach ; Recursive function to return the gcd of a and b ; Everything divides 0 ; Function to print the number of flips for both the sand timers ; Driver code
class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static void flip ( int a , int b ) { int lcm = ( a * b ) / gcd ( a , b ) ; a = lcm / a ; b = lcm / b ; System . out . print ( ( a - 1 ) + " ▁ " + ( b - 1 ) ) ; } public static void main ( String [ ] args ) { int a = 10 ; int b = 5 ; flip ( a , b ) ; } }