text: Minimum operations required to convert X to Y by multiplying X with the given co | C # implementation of the approach ; Function to return the minimum operations required ; Not possible ; To store the greatest power of p that divides d ; While divible by p ; To store the greatest power of q that divides d ; While divible by q ; If d > 1 ; Since , d = p ^ a * q ^ b ; Driver code
code: using System ; class GFG { static int minOperations ( int x , int y , int p , int q ) { if ( y % x != 0 ) return - 1 ; int d = y / x ; int a = 0 ; while ( d % p == 0 ) { d /= p ; a ++ ; } int b = 0 ; while ( d % q == 0 ) { d /= q ; b ++ ; } if ( d != 1 ) return - 1 ; return ( a + b ) ; } public static void Main ( ) { int x = 12 , y = 2592 , p = 2 , q = 3 ; Console . Write ( minOperations ( x , y , p , q ) ) ; } }