WA cutting recipes

http://www.codechef.com/viewsolution/5842794
Can’t figure out on which case is my code failing.

Problem is in this part :

if (c == 1)
{
   j = i;
   break;
}

Answer should be max of all such numbers encountered which divides each element of the array.
If you still get stuck then refer this corrected solution : http://ideone.com/2eLRFg

2 Likes

^Max of all such numbers which lies in range [1, s].

I am starting the loop from s to 2. So automatically the first divisor will be greatest. I found my mistake was that whenever(excluding first t =1) 1 was there in array the loop for(i=s;i>1;i–) failed. Changed it to

for(i=s;i>=1;i–) and it worked. Thanks for answering