__hermit__'s blog

By __hermit__, history, 4 years ago, In English

Hi , I have one expression as follows:-

(b*y) — (r)*floor(b*y/r)

b and r are known. We can set any value of y of our choice >=0 .

Now what are the possible value that this expression can take?

By running for some values of r and b, I observed two things:-

if (b%r==0) then the answer is zero (which seems obvious to me) if(b%r!=0) then answer is the following :- g*K where K>=0 and K<= (r/g)-1.

Can someone provide the proof for second case? Also will the answer for following expression be similer? r*ceil(b*y/r)-b*y

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

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

(b*y) — (r)*floor(b*y/r) is the same as (b*y)%r = (b%r) * (y%r) % r

If you are given b, then you know b%r.

So the values will be ((b%r) * 0) % r, ((b%r) * 1) % r, ..., ((b%r) * (r-1)) % r (some of these may be the same).