I have a mathematical problem that is part of my programming problem
I have a statement like
a = b%30;
How can I calculate b
in terms of a
?
I gave it a thought but couldn't figure it out.
I have a mathematical problem that is part of my programming problem
I have a statement like
a = b%30;
How can I calculate b
in terms of a
?
I gave it a thought but couldn't figure it out.
By definition,
b == 30*n + a
for some integer n
.
Note that there are multiple b
values that can give you the same a
:
>>> b = 31
>>> b % 30
1
>>> b = 61
>>> b % 30
1
First, obviously, there are in general several solutions for b
for a given a
.
If %
is the remainder operator found in most programming languages, then the sign of a
is critical. You know that this is a website for programming questions, right?
If |a|>=30, then there are no solutions
If a = 0, the solutions are the multiples of 30.
If 0 < a < 30, the solutions are all the b
such that b = 30 * k + a
for some positive integer k
.
If -30 < a < 0, the solutions are all the b
such that b = - (30 * k - a)
for some positive integer k
.