noob_is_my_name's blog

By noob_is_my_name, history, 5 years ago, In English

Problem link :- https://mirror.codeforces.com/gym/102948/problem/F

I am new to problem solving and was solving this problem, kindly help me with this :- My approach :- we can reach any lily pad which can be expressed in the form of x*N — y*M, x>= 0 && y>=0. So, I am using two loops to do so :-

for(ll i = 0; i<= l; i+= n) {

for(ll j = 0; (i + j) > 0 ;j-= m) {
       if(mp[i + j] == 1){
           mp[i + j] = 0;
           c++;
       }
   }

}

But, it is giving WA, since there was no editorial and I was unable to see other users submission, hence I am writing this blog.

  • Vote: I like it
  • -6
  • Vote: I do not like it

| Write comment?
»
5 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Something it's missing is this case 3 2 8 1 7

»
5 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

It can also be solved using the fact that it is always possible to reach some index i if thei is divisible by gcd(n, m).

Solution

  • »
    »
    5 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Your and my solutions get different results on this case 7 8 8 8 1 2 3 4 5 6 7 8