Given an integer N, the task is to find the minimum possible integer X such that X % M = 1 for all M from the range [2, N]
Input: N = 5
61 % 2 = 1
61 % 3 = 1
61 % 4 = 1
61 % 5 = 1
Input: N = 2
Approach: Find the lcm of all the integers from the range [2, N] and store it in a variable lcm. Now we know that lcm is the smallest number which is divisible by all the elements from the range [2, N] and to make it leave a remainder of 1 on every division, just add 1 to it i.e. lcm + 1 is the required answer.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Largest number by which given 3 numbers should be divided such that they leaves same remainder
- Count subarrays such that remainder after dividing sum of elements by K gives count of elements
- Largest number less than or equal to Z that leaves a remainder X when divided by Y
- Smallest subarray whose product leaves remainder K when divided by size of the array
- Minimum number of operations on a binary string such that it gives 10^A as remainder when divided by 10^B
- Find Quotient and Remainder of two integer without using division operators
- Ways of dividing a group into two halves such that two elements are in different groups
- Smallest number to make Array sum at most K by dividing each element
- Smallest number dividing minimum number of elements in the array | Set 2
- Smallest number dividing minimum number of elements in the Array
- Minimum decrements to make integer A divisible by integer B
- Find the minimum sum of distance to A and B from any integer point in a ring of size N
- Number of ways to obtain each numbers in range [1, b+c] by adding any two numbers in range [a, b] and [b, c]
- Total number of days taken to complete the task if after certain days one person leaves
- Count of nodes which are at a distance X from root and leaves
- Check if N leaves only distinct remainders on division by all values up to K
- Mimimum number of leaves required to be removed from a Tree to satisfy the given condition
- Minimize K whose XOR with given array elements leaves array unchanged
- Count number of digits after decimal on dividing a number
- Maximum value with the choice of either dividing or considering as it is
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.