Can anyone help in pointing out the mistake in my implementation of https://www.codechef.com/MAY18B/problems/RD19 I am getting WA. Here is my implementation:
asked 14 May '18, 22:33

The corrected solution: https://www.codechef.com/viewsolution/18574535 Firstly, observe the following:
In other words, if you delete any element, chances are, the common gcd will go up. Therefore, it is never possible to bring the common gcd down to 1 by deletion, if the common gcd of all the elements is greater than 1. Thus, the problem finally reduces to another problem, which asks you to print '0' if the common gcd is equal to 1, otherwise '1'. PS: Array index starts with 0. You cannot use 1based indexing. You are lucky because C++ does not have OutOfBoundsException. Other programming languages like Python or Java will throw a RE with a similar code! answered 15 May '18, 00:50
1
Thanks for your answer. Since the problem explicitly said "find the minimum number of elements which have to be deleted", I fell for it..
(15 May '18, 22:21)
No problem buddy. I hope you learnt something. :)
(15 May '18, 22:55)

Two problems: First, a[n] defines an array with elements a[0],a[1], ..., a[n1]. So your loops should have the form
Second, the minimum number of elements to be deleted is 0 or impossible. It is incorrect to output c as an answer. answered 15 May '18, 01:08
