0

a and c are Integer constants, where a<c.

x belongs to the set of Natural Numbers.

How to maximize the result of (a*x)%c?

Over here if we assume that b=0 then the solution given in the answer doesn't work.

Suggested Answer for maximization of (ax +b)%c:-

if(0 != (c-b)%a) ) {max = c-((c-b)%a);} else {max=c-a;}

Suppose a=15,c=21 and b=0 then according to this post the answer should be:-

max = 21-((21-0)%15)

max = 21-(21%15)

max=21-6

max=15

but for x=4 we get the result ax%b as 15*4 % 21 which is 60%21 or 18.

  • 1
    I'm sure we just had this question a few days ago, but I can't find it. The maximum value is $c-\gcd(a,c)$. – Gerry Myerson Apr 12 '19 at 05:22
  • 1
    See https://math.stackexchange.com/questions/3177986/construct-an-algorithm-to-find-the-multiple-of-a-such-that-ab-is-maximized and https://math.stackexchange.com/questions/3177895/what-is-maximum-value-of-a-b-mod-c-where-a-and-c-are-known – Gerry Myerson Apr 12 '19 at 05:34

0 Answers0