Minimum integer such that it leaves a remainder 1 on dividing with any element from the range [ 2 , N ] | Function to return the smallest number which on dividing with any element from the range [ 2 , N ] leaves a remainder of 1 ; Find the LCM of the elements from the range [ 2 , N ] ; Return the required number ; Driver code
function getMinNum ( N ) { var lcm = 1 ; for ( var i = 2 ; i <= N ; i ++ ) lcm = ( ( i * lcm ) / ( __gcd ( i , lcm ) ) ) ; return ( lcm + 1 ) ; } function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } var N = 5 ; document . write ( getMinNum ( N ) ) ;