2
$\begingroup$

Pretty much every thing is in the title, really! I'm trying to come up with an efficient algorithm to factorize large integer as an homework for a parallel programming course.

I've seen a few pages explaining the algorithms, but just can't wrap my head around the notation enough to actually implement the thing.

For exemple, in the very beginning, to demonstrate inefficiency of Fermat's Factirization for primes whose factors are nearer 1 than from the square root we have for n=1649:

         41^2 - n = 32         42^2 - n = 115         43^2 - n = 200 ... and then         41^2 ≡ 32 (mod n),           43^2 ≡ 200 (mod n),   we have          41^2 * 43^2 ≡ 80^2 (mod n),    that is,          (41 * 43)^2 ≡ 80^2 (mod n). 

What does the (mod n) stands for?

I understand the modulo operator, as used in many programming language, but I'm not sure whether this is what is meant here as I can't figure what are his operands, in that context...

Thank you very much, Pascal

  • 1
    In computer science mod is a binary operator, in mathematics $x \equiv y \ (\mod z)$ is a relation, the computer-science equivalent of which would be x mod z = y mod z.2012-04-12

2 Answers 2

5

A useful way to think about $a \equiv b$ (mod $n$) is "$a$ and $b$ have the same remainder when divided by $n$".

1

The statement $x \equiv k \pmod n$ means that $\frac{x-k}{n}$ is an integer, (note this requires $n \neq 0$). Equivalently, $x = mn + k$ for some integer $m$.

In this case we have $n=1649$, and the statment $41^2 \equiv 32 \pmod n$ means that $41^2$ is 32 more than a multiple of $1649$.

The notation translates from programming (ignoring possible overflow) as follows:

x % n == k // True

implies

$x \equiv k \pmod n$.

If $x\geq 0$ and $k$ is the smallest positive integer for which $x \equiv k \pmod n$, then x % n == k. (This is true in C and Javascript at least, I just tested).

For example 10 % 3 == 1 implies $10 \equiv 1 \pmod 3$, and $10 \equiv 1 \pmod 3$ implies 10 % 3 == 1. But, $10 \equiv 4 \pmod 3$, does not imply 10 % 3 == 4.

If $x \leq 0$ and $k$ is the largest negative integer (smallest absolute value) for which $x \equiv k \pmod n$, then x % n == k.

That is, the modulo operator in most programming languages keeps the sign of the number.

  • 0
    To $b$e honest, I considered making the distinction when I was writing my post, $b$ut I decided a$g$ainst it. He said he is aware of the modulo operator already and just wanted to know how the mathematical notation is read. I will update my comment shortly.2012-04-12