Covid Run Codechef October long challenge problem solution| Codechef October long challenge problem solution -
This is very first and easy problem of Codechef October long challenge problem solution| Codechef October long challenge problem solution.
2 6 2 5 3 12 3 4 2
read More-Positive AND Codehef October long challenge Solution |CodeChef October long challenge editorial
read more-Covid Run Codechef October long challenge problem solution| Codechef October long challenge problem solution
Let's directly jump into solution
according to problem statement take input t= total number of test cases .
next line contain n,k,xand y
take input for n,k,x and y.
virus is currently at city x.
spreading rate of virus is k means virus can jump k city from its currenty position x.
Question says that you are living currently at y city so you have to tell that virus may infect you or not.
Approach of this question is very simple simply you have to jump k step from current city and if this goes out of (N-1) city it will
return back to city (n+k)%n th city.
dont try to think too much follow steps as mentioned in question it is called bruete force approach.
My approach says that if the virus currently at city x in the next step it will jump to (x+k)%n th city.
What i will do i will maintain a flag variable that will tell me that virus can reach to place y or not.
step 1-If virus already at position y. so i have to simply return true.otherwise, I will move form current city to x+k th city.in this case i will mark my flag as true and terminate the loop.
step 2- if virus reach again at x position it mean it will never reach to city y and the person who is sitting in city y is safe.
in this case i will mark my flag as false and terminate the loop.
finally, i will print the result according to the flag
Entire code solution is given below-