Chef 's chick gone wrong .....please help me out

Please tell why my code is wrong it satisfy the sample input .

question : CHFCHK Problem - CodeChef

my submission : CodeChef: Practical coding for everyone

Try this test-case

1
4
4 6 7 8

Correct answer is 4 but your code gives 5

what should i do to correct it please tell

Your approach is incorrect as you are just taking only first 100 multiples of each element, which leads to the increment in difference because the multiples of smaller elements are not present in your vector but according to the question it is infinitely long so we would need all the multiples of all the provided elements and this would not be a good method to perform.
But if you look at the problem, it asks for smallest y > x and y should be multiple of at least one of the elements so we will jump on all the multiples of all the given elements due to which
the maximum jump would always be equal to the smallest of the given elements.
So you just have to find the minimum of the all the given elements.

1 Like

Simple is better than Complex …
it worked thanks for the hint q

1 Like