andreyDagger's blog

By andreyDagger, history, 9 months ago, In English
  • Vote: I like it
  • +37
  • Vote: I do not like it

By andreyDagger, 23 months ago, In English

Let $$$m$$$ be some positive integer (not necessary prime) . There is a way to calculate $$$\displaystyle{\frac{a}{b}}\%m$$$ when b is not very big and $$$a \% b = 0$$$ Firstly, let's notice, that $$$\displaystyle{\frac{a}{b}}=mk+(a/b)\%m$$$, for some integer value k. Now, let's do some mathematical stuff:

$$$\displaystyle{\frac{a}{b}}=mk+\displaystyle{\frac{a}{b}}\%m$$$
$$$a=mbk+b(\displaystyle{\frac{a}{b}}\%m)$$$
$$$(a\%mb)=b(\displaystyle{\frac{a}{b}}\%m)$$$
$$$(a\%mb)/b=\displaystyle{\frac{a}{b}}\%m$$$

So, the answer is $$$(a\%mb)/b$$$

Full text and comments »

  • Vote: I like it
  • +17
  • Vote: I do not like it