Блог пользователя __hermit__

Автор __hermit__, история, 4 года назад, По-английски

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

  • Проголосовать: нравится
  • -1
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

(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).