Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

**Harold****Guest**

Can you help me with these two problem

-23 mod 5

23 mod -5

and,could you please explain modulo with nagetive number?

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Hi;

If you use this formula you will have no problems with modulo.

Where

is called the floor function and is evaluated like this:

and

it always rounds down to the smallest integer.

Let's do the first one:

-23 mod 5

You are looking for r, the remainder. a = -23 and m is the modulo, in this case 5.

Now

So -23 mod 5 is 2.

You try the second one. Let me know what you get.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**Harold****Guest**

It is -2,is nagetive number allowed as result?

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Hi;

Yes, unless you are told it must be positive.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**Harold****Guest**

Thank you^infinity

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Hi;

You are welcome. Were you able to do the second problem?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**bob bundy****Administrator**- Registered: 2010-06-20
- Posts: 8,065

hi bobbym,

Yes he has (in post 3). He got -2

The definition for modulo regarding + or - is uncertain. See http://en.wikipedia.org/wiki/Modulo_operation

Harold ought to check how it has been defined by his teacher.

Bob

Children are not defined by school ...........The Fonz

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Hi;

Yes he has (in post 3). He got -2

I see that now. He got the right answer too.

Sometimes it has to be the same sign as the divisor. I gave him the one that gets the same answers as Wolfram would.

Unfortunately he skeddadled right after he solved it. I wanted to go a little deeper.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**Harold****Guest**

Guys,I have another problem,my brother says that 23 mod -5 will be 3 as Euclidean division states a=bq+r and the division will be 23=(-5)*(-4)+3.

**bob bundy****Administrator**- Registered: 2010-06-20
- Posts: 8,065

hi Harold,

In effect, that was my point in post 7.

The following are all equivalent mod 5

-12, -7, -2, 3, 8, 13, 18 ......

Basically just add 5.

If you follow my link to Wiki you will see that two definitions are possible and there are even more variations amongst computer languages.

Your brother is right using the 'Euclidean division' definition ... under this no negatives are allowed.

Which is why I think you need to check with your teacher / tutor and see what definition is required.

Bob

Children are not defined by school ...........The Fonz

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**Harold****Guest**

I am sorry to bug again but after you gave me the formula,i experimented a little and solution to -23 mod -5 results -43,is it correct

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Hi;

I am getting -3 as the answer. Can I see what you have done?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**bob bundy****Administrator**- Registered: 2010-06-20
- Posts: 8,065

Looks like -23 - 20 = -43 rather than -23 + 20 = -3

There are a lot of minus signs to take account of. Easy to slip up on that.

Bob

Children are not defined by school ...........The Fonz

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Hi;

I am getting

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**Harold****Guest**

You're right,i missed a minus sign,thank you a lot,you guys taught me a lot of things today.

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Hi Harold;

Use a calculator to at least check.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**bob bundy****Administrator**- Registered: 2010-06-20
- Posts: 8,065

Am I right about this:

The formula should always give a value x, so that -m < x < m (assuming m is positive ... reverse the signs otherwise)

Bob

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Hi bob;

If you did that what do you get for -65 mod -17?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**bob bundy****Administrator**- Registered: 2010-06-20
- Posts: 8,065

Good morning bobbym

Bob

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Hi Bob;

Good Morning.

That is what I am getting too.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**bob bundy****Administrator**- Registered: 2010-06-20
- Posts: 8,065

My point was that Harold can eliminate obvious errors such as -43 on the grounds that it is out of range.

Bob

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Hi;

Yes, it is an obvious error, the answer can never exceed m. In either direction.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline