Smallest positive integer X satisfying the given equation | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findMinSoln ( int n , int k ) { int minSoln = INT_MAX ; for ( int i = 1 ; i < k ; i ++ ) { if ( n % i == 0 ) minSoln = min ( minSoln , ( n / i ) * k + i ) ; } return minSoln ; } int main ( ) { int n = 4 , k = 6 ; cout << findMinSoln ( n , k ) ; }