Find the largest possible value of K such that K modulo X is Y | Python3 program for the above approach ; Function to find the largest positive integer K such that K % x = y ; Stores the minimum solution ; Return the maximum possible value ; Driver Code
import sys NEW_LINE def findMaxSoln ( n , x , y ) : NEW_LINE INDENT ans = - sys . maxsize NEW_LINE for k in range ( n + 1 ) : NEW_LINE INDENT if ( k % x == y ) : NEW_LINE INDENT ans = max ( ans , k ) NEW_LINE DEDENT DEDENT return ( ans if ( ans >= 0 and ans <= n ) else - 1 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 15 NEW_LINE x = 10 NEW_LINE y = 5 NEW_LINE print ( findMaxSoln ( n , x , y ) ) NEW_LINE DEDENT