Aditya_Dave's blog

By Aditya_Dave, history, 16 hours ago, In English

697A - Pineapple Incident ==============: In this question, we are told that the pineapple barks at t, t+s, t+s+1, and so on. One way is to check for each and every multiple of s by applying a for loop, but it will be too lengthy and time consuming. Another way is:

if t+n*s=x or t+n*s+1=x,(where n is any natural number), then it can be clearly seen that (x-t) or (x-t-1) is divisible by s. But here we need to be careful when t>x. This will be our edge case. If t>x, then the pineapple will not bark at the time x. So we can clearly output NO as our answer. If this condition (x-t)%s==0 || ((x-t-1)%s==0 && (x-t-1)/s!=0) satisfies, then we can clearly print YES, else we can print NO. 298127756

  • Vote: I like it
  • 0
  • Vote: I do not like it