Solving Modulo Arithmetic Problem with Variable Integer k

  • Thread starter Mentallic
  • Start date
  • Tags
    Arithmetic
In summary, the conversation discusses an arithmetic problem involving a set of integers and a variable integer. The goal is to find the smallest integer t such that kt is greater than or equal to the constant m, and if kt is also less than the constant n, the output should be kt. However, if kt is greater than n, the output should be n. The conversation also mentions a potential method for implementing a non-piecewise function, using the min(a,b) and abs(x) functions.
  • #1
Mentallic
Homework Helper
3,802
95
I've stumbled across an arithmetic problem that's getting the better of me, so I need your help!

I have a constant set of integers [itex][m,n], m>0, m\neq n[/itex] and a variable integer k>0. If we multiply k by successively increasing positive integers t, we will eventually get kt > m. Now, what I want is the output to be kt if [itex]kt \in [m,n][/itex] and n if [itex]kt>n[/itex].

So for example, let's consider m = 45, n = 50 and k = 8.

We get the sequence 8, 16, 24, 32, 40, 48

At this point, we have a value larger or equal to m=45, and 48 < n=50 so the output is 48.

For k=11 we have
11, 22, 33, 44, 55

Since we now have a value larger than m, but the value is also larger than n, the output needs to be n=50.

So finally, my question is, can I create a function that isn't piecewise that defines this process? The piecewise function wasn't such a big deal,

$$
f(k,m,n) =
\begin{cases}
\Big\lceil \frac{m}{k} \Big\rceil k, & \text{if}\hspace{5 mm} \Big\lceil \frac{m}{k} \Big\rceil k < n \\ \\
n, & \text{if}\hspace{5 mm} \Big\lceil \frac{m}{k} \Big\rceil k \geq n
\end{cases}
$$


But I can't figure out how to produce a non-piecewise function.
 
Physics news on Phys.org
  • #2
[m,n] means the interval from m to n?

So t is the smallest integer t such that kt >=m?

You can implement min(a,b) (the smaller value of a and b) as (|a+b|-|a-b|)/2, I think that should help.
 
  • #3
mfb said:
[m,n] means the interval from m to n?

So t is the smallest integer t such that kt >=m?

Yes and yes. Sorry, I should have been more clear when defining my variables.

mfb said:
You can implement min(a,b) (the smaller value of a and b) as (|a+b|-|a-b|)/2, I think that should help.

That's perfect! Thanks mfb.
 
  • #4
Mentallic said:
So finally, my question is, can I create a function that isn't piecewise that defines this process?

mfb said:
You can implement min(a,b) (the smaller value of a and b) as (|a+b|-|a-b|)/2.
Now a method to implement absolute value that isn't piecewise would be needed.
 
Last edited:
  • #5
Good point, but this problem was actually for a computing project of mine and since the abs(x) function already exists as a library function, its piecewise definition isn't an issue.
 
  • #6
For 32 bit signed two complement integers, and assuming the compiler does an arithmetic right shifts:

#define abs(a) ((a^(a>>31))+((a>>31)&1))
 

Related to Solving Modulo Arithmetic Problem with Variable Integer k

What is modulo arithmetic?

Modulo arithmetic is a mathematical operation that finds the remainder when one integer is divided by another. It is denoted by the symbol % and is commonly used in computer programming and cryptography.

How do you solve a modulo arithmetic problem?

To solve a modulo arithmetic problem, you need to divide the first integer (dividend) by the second integer (divisor). The remainder of this division is the solution to the problem. For example, if we have the problem 17 % 5, the solution would be 2 (since 17 divided by 5 leaves a remainder of 2).

What is the purpose of using a variable integer k in a modulo arithmetic problem?

In some modulo arithmetic problems, the value of the dividend or divisor may change. In these cases, using a variable integer k allows us to represent any value in the problem, rather than just a specific number. This makes the solution more versatile and applicable to a wider range of problems.

What are some real-life applications of modulo arithmetic?

Modulo arithmetic has many practical applications, such as calculating time on a clock, determining leap years, and encrypting data in cryptography. It is also used in computer science to perform calculations that involve repeating patterns, such as in graphics and sound processing.

What are some common misconceptions about modulo arithmetic?

One common misconception about modulo arithmetic is that it is the same as division. While the two operations may seem similar, they have different purposes and produce different results. Another misconception is that modulo arithmetic can only be applied to positive integers. In reality, it can be used with negative integers as well.

Similar threads

  • Precalculus Mathematics Homework Help
Replies
8
Views
1K
  • Calculus and Beyond Homework Help
Replies
7
Views
2K
  • Precalculus Mathematics Homework Help
Replies
2
Views
2K
  • Precalculus Mathematics Homework Help
Replies
7
Views
1K
  • Introductory Physics Homework Help
Replies
12
Views
764
  • Advanced Physics Homework Help
Replies
10
Views
1K
  • Advanced Physics Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Atomic and Condensed Matter
Replies
3
Views
907
  • Calculus and Beyond Homework Help
Replies
3
Views
330
Back
Top