What's the correct algorithmic expression?

176 Views Asked by At

I've got the following logic which I'm trying to find a formula for it.

Say we have the constants A, B, C.

I'm trying to find a formula to calculate C while following this logic.

If A = 1 then whatever is B, C = 0
If B = 1 then whatever is A, C = 0

If A = 2, B = 2 or 3, C = 1
If A = 2, B = 4 or 5, C = 2
If A = 2, B = 6 or 7, C = 3
... etc for A = 2

If A = 3, B <= 2, C = 0
If A = 3, B is between 3 to 5, C = 1
If A = 3, B is between 6 to 8, C = 2
If A = 3, B is between 9 to 11, C = 3
... etc for A = 3

If A = 4, B <= 3, C = 0
If A = 4, B is between 4 to 7, C = 1
If A = 4, B is between 8 to 11, C = 2
If A = 4, B is between 12 to 15, C = 3
... etc for A = 4

Etc for all multiples of A.

I thought about doing it like that, in pseudo algorithms :

IF A = 1 OR B = 1
    C = 0
ELSE
    IF B < A
        C = 0
    ELSE
        C = INT(B/2) // INT function is used to get the integer of the result

But unfortunately this doesn't cover all cases, and I can't seem to figure out how can I cover all cases. Any help is appreciated !

1

There are 1 best solutions below

3
On BEST ANSWER

If $A=1$ then $C=0$ else $C=\lfloor B/A\rfloor$.