Find minimum x such that ( x % k ) * ( x / k ) == n | C # Program to find the minimum positive X such that the given equation holds true ; This function gives the required answer ; Iterate over all possible remainders ; it must divide n ; Driver Code to test above function
using System ; public class GFG { static int minimumX ( int n , int k ) { int ans = int . MaxValue ; for ( int rem = k - 1 ; rem > 0 ; rem -- ) { if ( n % rem == 0 ) ans = Math . Min ( ans , rem + ( n / rem ) * k ) ; } return ans ; } static public void Main ( ) { int n = 4 , k = 6 ; Console . WriteLine ( minimumX ( n , k ) ) ; n = 5 ; k = 5 ; Console . WriteLine ( minimumX ( n , k ) ) ; } }