c# - Find the closest higher number that has a given divisor -


i have allocate items customers. in allocation algorithm customers should have specific minimum, before allocate remaining items.

some of these items pre-picked. these pre-picked items @ least 1 container quantity given. two.

i need efficient algorithm find minimum value above given minimum value per customer , can divided @ least 1 container quantity without remainder.

here minimalistic code better understanding:

int  containerqty1;      int? containerqty2;     // can null int customerminimum;   int minimumtoget; 

in example, minimumtoget should have higher value customerminimum, has divided without remainder containerqty1 or containerqty2.

given 2 numbers, m , d, can construct smallest number x above m such d divides x first adding d m, , subtracting remainder of division of sum d, i.e.

int x = (m+d) - ((m+d) % d); 

example: m = 200, d = 13. looking smallest multiple of 13 above 200.

int x = (200+13) - ((200+13) % 13) = 213 - 5 = 208; 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -