Minimum integer such that it leaves a remainder 1 on dividing with any element from the range [ 2 , N ] | C ++ implementation of the approach ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; long getMinNum ( int N ) { int lcm = 1 ; for ( int i = 2 ; i <= N ; i ++ ) lcm = ( ( i * lcm ) / ( __gcd ( i , lcm ) ) ) ; return ( lcm + 1 ) ; } int main ( ) { int N = 5 ; cout << getMinNum ( N ) ; return 0 ; }