Smallest positive integer X satisfying the given equation | Java Program to implement the above approach ; Function to find out the smallest positive integer for the equation ; Stores the minimum ; Iterate till K ; Check if n is divisible by i ; Return the answer ; Driver Code
import java . util . * ; class GFG { static int findMinSoln ( int n , int k ) { int minSoln = Integer . MAX_VALUE ; for ( int i = 1 ; i < k ; i ++ ) { if ( n % i == 0 ) minSoln = Math . min ( minSoln , ( n / i ) * k + i ) ; } return minSoln ; } public static void main ( String [ ] args ) { int n = 4 , k = 6 ; System . out . println ( findMinSoln ( n , k ) ) ; } }