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
.