These problems were all from Kaloyan, who has given us a number of interesting questions. The first was at the very end of November:

ABC is a right triangle (angle C is right). If the area of the triangle is 600 and the line passing through the centroid and the incenter is parallel to BC, find the lengths of AC and BC.See the attachments for the diagram I made using GeoGebra. I really don’t know how to start and approach the problem.

We know that the line in the problem is parallel to BC, so it’s also perpendicular to AC and it passes through the incenter J, so the intersect T is actually the tangent point.

Can you give me a hint?

(I have redrawn his image, which was hard to read.)

The **incenter**, *J*, is the center of the **incircle**, which is tangent to the sides of triangle *ABC*. The **centroid**, *H*, is where the medians (including \(BB_1\) and \(CC_1\)) intersect. The larger circle shown, through the vertices of the triangle, is the **circumcircle**, whose center, the circumcenter, is \(C_1\), the midpoint of the hypotenuse; this is not necessarily relevant to the problem itself, but by drawing it first, we can move C to create a variable right triangle and adjust it to fit the condition.

We are told that *HJ* is parallel to *BC*, which makes it perpendicular to side *AC*, and therefore the intersection, *T*, is the point of tangency of the incircle.

Given the area, how can we find the legs of the triangle?

Doctor Rick answered, with just a very small hint (because we know from experience that Kaloyan can think well!):

Hi, Kaloyan.

I can solve the problem, though there might be a nicer method than mine; it involved an equation that looked pretty ugly at first.

Here’s a hint: You can find the

ratio of the inradius r to the length of AC, which I called x. If you don’t see this,draw the median from A.

Here is the same drawing, showing two radii *r* and labelling side *x* (which I’ve called by its traditional name *b*), and the median from *A* (\(AA_1\)):

The hint is to find the ratio *r* : *b*.

Kaloyan replied:

Thank you for the response, Doctor Rick!

But what you wrote is so brief, I cannot even get started. What are we using, etc? May I ask you to be more detailed in your explanations?

Within an hour, though, he had solved it (though not in a way he liked):

Hello again,

Let me show you what I came up with using your hint:

After the system, everything left is just algebra.

I think that the solution is good. Together we succeeded in finding an adequate solution! Yey! ?

Maybe we can find something else involving more geometry, rather than algebraically solving a system?

Let’s think through this work, before looking for another way.

In the upper right, after saying that \(CT=p-c\), which makes no sense to me (I suspect, as we’ll see, that he meant \(s-c\), where *s* is the semiperimeter), he gives a formula for the inradius of a right triangle, \(r=\frac{a+b-c}{2}\), which we’ll discuss below. (It doesn’t work for a general triangle, but is equivalent to \(s-c=\frac{a+b+c}{2}-c\), a nice way to memorize it.)

Then he writes a proportion, $$\frac{AC}{CT}=\frac{AA_1}{MA_1}=\frac{3}{1}$$ This represents the known fact that the centroid divides each median in the ratio 2:1, and that triangles \(ACA_1\) and \(ATM\) are similar.

Flipping this, the proportion $$\frac{CT}{AC}=\frac{1}{3}$$ becomes $$\frac{a+b-c}{2b}=\frac{1}{3}$$ since \(CT=r=\frac{a+b-c}{2}\) and \(AC=b\).

He combines this with the equation for the area (with *a* and *b* as base and height), $$\frac{ab}{2}=600,$$ and the Pythagorean theorem $$a^2+b^2=c^2,$$ making a system of three equations in three unknowns. The rest, as he says, is “just algebra”: He rewrites the first equation as $$3a+b=3c,$$ then squares it to get $$9a^2+6ab+b^2=9c^2$$ and changes the RHS using the third equation, $$9a^2+6ab+b^2=9a^2+9b^2,$$ cancels and replaces \(ab=1200\) from the second equation to get $$7200=8b^2,$$ so that \(b=30\) and, from the second equation, \(a=40\). With such a nice answer, surely there is an easier way …

Doctor Rick approved:

I was writing with more hints, but I see that you didn’t need any more after all. You got the answer I got; at a glance it’s not the same method I used – which is good! I will take a look at it when I can.

Soon he wrote again, with thoughts about the formula, deriving it to show his own way of thinking:

There are several places where I cannot decipher your handwriting, but I think I can follow most of it. One thing I need to think more about is where you write (upper right):

r = (a + b â€“ c)/2 … [1]

Is that a formula you knew for the

inradius of a right triangle? I don’t have such a formula memorized;what I remember easily is

K = rs… [2]where K is the triangle area, r is the inradius, and s is the semiperimeter, s = (a + b + c)/2. In the case of a right triangle, K = ab/2 and c

^{2 }= a^{2 }+ b^{2}, so we haveab/2 = r(a + b + c)/2

r = ab/(a + b + c)

I can use the fact that

(a + b + c)(a + b â€“ c) = (a + b)

^{2 }â€“ c^{2}= (a

^{2 }+ 2ab + b^{2}) â€“ (a^{2 }+ b^{2})= 2ab

to conclude that

2ab/(a + b + c) = a + b â€“ c

thus deriving your formula [1], which makes your work cleaner than mine. I started from [2] and obtained an ugly radical equation.

What might that “ugly radical equation” be? Probably something like this: $$r(a+3r+\sqrt{a^2+9r^2})=1200$$ I can get the solution from this, but it isn’t easy. The “preprocessing” of turning his \(K=rs\) into \(r=s-c\) for the right-triangle case greatly simplifies the work.

He continued:

Just now I came up with a

“more geometrical” solution, which I will describe briefly. Having established that r = b/3, we turn our attention to the incircle, as in this figure:Consider the areas of the six triangles into which the blue line segments divide ABC. You can write the sum of their areas in terms of EO = DO = FO = r and AE = a â€“ r. Compare this to ab/2 = 3ar/2, and you can obtain a = 4r = (4/3)b, from which the desired result follows when we use the additional information that ab/2 = 600.

Let’s fill in some details on this geometrical solution (which starts with the area formulation of the inradius that leads to the formula \(K=rs\)):

(Parts of *AB* are marked as equal to corresponding parts of *AC* and *BC*, because they are tangents from the same points.)

What I see to do is to write the area as the sum of a square and two pairs of congruent triangles, namely $$K=r^2+r(a-r)+r(b-r)=ar+br-r^2.$$ Replacing *b* with 3*r*, and setting this equal to \(K=\frac{ab}{2}=\frac{3ar}{2}\), we get the equation $$ar+3r^2-r^2=\frac{3ar}{2},$$ which simplifies to \(2r^2=\frac{ar}{2}\), so that \(a=4r\).

The given area then yields the equation $$\frac{(4r)(3r)}{2}=600$$ so that \(r^2=100\) and \(r=10\). Consequently, \(a=4(10)=40\) and \(b=3(10)=30\).

Kaloyan responded with information about the formula:

Yes. It can be derived really easy, but it’s

something that we are taught to remember here in Bulgaria. Let me briefly describe the idea for the proof using your diagram. CE = CD = r because CEOD is a square. CE and CD are tangent segments to the incircle and as such their length iss – c= (a + b + c)/2 â€“ c =(a + b – c)/2(s is the semiperimeter of ABC).This

formula for tangent segmentsis valid forevery triangleand its incircle. Let the incircle touches AB, BC, AC at M, N, P, respectively. Let AM = AP = x, then BM = BN = c – x and CP = CN = b – x. Using BC = BN + CN, we get c-x+b-x = a, adding a to both sides gives a+b+c-2x = 2a, or x = (a + b + c – 2a)/2 = (p – 2a)/2 = p/2 – a = s – a.Nice “more geometrical” solution!

The general formula he demonstrates is not about the inradius *r*, but that the tangent segments at *A* have length \(x=s-a\); this is *r* if *A* is a right angle. Here is his figure:

Doctor Rick concluded:

Yes, there can be lots of ways to prove things!

I showed you

derivation of your formula for the inradius of a right triangle from K = rs. Having not taught geometry, I only remember essential formulas (largely those I can derive on the fly, like K = rs). The more you know, the more ways something can be done.myMy “more geometric” solution of your problem has strong connections both to your derivation using tangent segments and to my derivation using areas.

It’s often interesting to see that work without a special tool like the incenter formula can in a sense recreate the derivation of the formula itself; so the formula encapsulates part of the proof. Here, we’ve seen two different derivations of the same formula, and both are reflected in the non-formulaic work on the main problem.

The next day, Kaloyan had another question, and made considerable progress while explaining the problem to us:

A right triangle ABC is given with right angle at C. The catheti are 6 and 8. A circle is constructed through the midpoint of the smaller cathetus and the midpoint of the hypotenuse such that it touches the hypotenuse. Find the area of the circle.I don’t know if the way we have the circle constructed is clear, as English isn’t my native tongue. I will try to paraphrase it in one more way:

k is a circle: the midpoint of the smaller cathetus lies on k, the midpoint of the hypotenuse lies on k and k also touches the hypotenuse.I can’t even make a diagram as I don’t imagine how the circle will look. So if K is the midpoint of the cathetus and N is the midpoint of the hypotenuse, the center of the circle will lie on the perpendicular [bisector of] segment KN, but what else?

Thank you!

(If you, like me, are unfamiliar with the term cathetus, and its plural catheti, it comes from Greek meaning “perpendicular distance, as a fishing line falling to the water”, and means one of the perpendicular sides of a right triangle. Translation, in this case from Bulgarian, can lead to unexpected word choices.)

Half an hour later he added a picture and some thoughts:

I was able to draw this:

I think that

the circle must touch the hypotenuse exactly at its midpointbecause we know that the circle touches the hypotenuse, this meaning that it only has 1 common point with it, and the circle also passes through the midpoint of the hypotenuse => it touches the hypotenuse at its midpoint, right? Can you show me a good proof of this statement?So let’s draw a perpendicular from N to AB and the intersection with the perpendicular bisector [of KN] is going to be the center.

What can I note next? I can’t find a relation between the given triangle and the radius of the circle.

*N*, the midpoint of the hypotenuse, is labelled *P* in the picture, leading to a little confusion. (I’ll be calling it P.) He is right that we could construct the center, *O*, as the intersection of the perpendicular bisector of *AB* (because of the tangency), and the perpendicular bisector of *KP*, which is a chord of the circle.

Doctor Rick answered again, confirming the interpretation and offering a hint:

Hi, Kaloyan.

The problem is:

A right triangle ABC is given with right angle at C. The catheti are 6 and 8. A circle is constructed through the midpoint of the smaller cathetus and the midpoint of the hypotenuse such that it touches the hypotenuse. Find the area of the circle.

First let me say that I had to look up the word “cathetus”; in the USA it is commonly called a “

leg” of a right triangle.Where the problem says “

touchesthe hypotenuse”, I would say it “istangentto the hypotenuse.” I take it to mean exactly what you also think: that the circle is tangent to the hypotenuse at its midpoint. A circle cannot be tangent to a line and also intersect the line at apoint.differentSo here is a restatement of the problem:

A right triangle ABC is given, with right angle at C. The legs are 6 and 8. A circle is constructed through the midpoint of the smaller leg, and tangent to the hypotenuse at its midpoint. Find the area of the circle.

You are on the right track. Let’s give the midpoint of AB the label P, and the midpoint of KP the label Q. You’re saying, correctly, that the center O of the circle k is at the intersection of the perpendicular bisectors of AB and of KP. Now look at the triangle OQP. Is it similar to another triangle?

Here is a picture with these labels (which I have corrected from what he actually wrote based on the confusion of the name of P):

In the next half hour, Kaloyan wrote three times, first asking about the misstated labels and then moving on without further help:

I figured it out myself. My labels: the midpoint of AB is P, the midpoint of AC is K. I think you meant that we should look at the midpoint of KP. Let’s give it the label Q. Now the triangle OQP is similar to PKA which gives r/5 = 2/3 => r = 10/3 and the area is \(100/9*\pi\).

He has used the fact that \(\triangle PKA\sim\triangle BCA\), so that each side of the former is half of the corresponding side of the latter, namely 3, 4, and 5; and then, since \(\triangle OQP\sim\triangle PKA\), he wrote the proportion $$\frac{OP}{PA}=\frac{PQ}{AK}\\\frac{r}{5}=\frac{2}{3}$$ This gives \(r=\frac{10}{3}\) and the area of the circle is $$\pi r^2=\pi\left(\frac{10}{3}\right)^2=\frac{100\pi}{9}.$$

I also found 2 ways to

showthat the trianglesOQP and PKA are similar.1) if angle

OPQis x, then angleAPKis 90-x and anglePAKis 90 â€“ (90 â€“ x) = x.2) the corresponding

arcto angle KPA is KP. KP is also the corresponding arc to angle KOP. So if angle KPA is x, then angle KOP is 2x. OQ is the angle bisector which makes angle QOP = x.

The second explanation uses the theorem that the angle between a tangent and a secant to a circle is half of the central angle subtended by the arc.

Doctor Rick replied:

Yes, that’s what I saw.

The way I see that triangles ABC and POQ are similar is that

corresponding sides are perpendicular. That is, AB is perpendicular to PO, BC is perpendicular to OQ, and CA is perpendicular to QP.

There are often multiple ways to see that two triangles are similar!

]]>

Here is a 1999 question about a special number:

Prime Factors of 4,194,305 I am in 8th grade and taking Algeom (algebra and geometry in one year). Our teacher assigned the problem: Prime Factor 2^22+1 I have spent about 2 hours on the problem so far, and have talked to 2 of my classmates about it. I have been unable to make any progress other than finding out that one of the factors is 5. I worked out the number, which is4194305, which isobviously divisible by 5. I then found a program on the Internet that gives the prime factorization of a number. I entered my number and got 5*397*2113. We are supposed to show how we got our answer. I would like to know if you have a clever way to do this problem. I would appreciate it greatly.

It was easy to find the first factor, 5; but we need a powerful method to factor the rest, \(4,194,305\div5=838,861\).

Doctor Schwa answered with a custom-made approach based on the known form of the number:

Interesting question, and I like your approach. I tried to do it with a little algebra. Maybe you've learned by now that (x+1)^2 = x^2 + 2x + 1. Well, 2^22 + 1 looks sort of like that, except there's no 2x there. Rats. I thought for a while about how to put a 2x in there, and finally decided on thiswishful thinking strategy: 2^22 = (2^11)^2, so if x = 2^11, then I have x^2 + 1. How do I get the 2x? I just stuck it in there. But wait, that's not fair, so I better subtract it, too, like this: 2^22 + 1 = 2^22+ 2*2^11+ 1- 2*2^11. Now I have that perfect square factoring pattern, but with a -2*2^11 left outside: = (2^11 + 1)^2 - 2*2^11. And 2*2^11 = 2^12, so = (2^11 + 1)^2 - 2^12 But 2^12 = (2^6)^2, so = (2^11 + 1)^2 - (2^6)^2 and now I use the 'Difference Of Two Squares' factoring pattern: =(2^11 + 1 + 2^6)(2^11 + 1 - 2^6)which equals = (2113)(1985) or (2113)(397)(5), the same answer you got. Thanks for a fun problem. I wonder if my method is what your teacher had in mind?

Doctor Schwa used a very similar approach to factor a quartic polynomial hereÂ (near the bottom).

We’ll see another way using the difference of squares below.

Now, what if the number is *really* large, and doesn’t have a special form?

Here is a question from 2000, in which we’ll apply two methods to the same number, 1037:

Factoring Large Numbers I am doing a report on Fermat and it says he developed a method for factoring large numbers. The theorem goes something like this: "If p is a prime number, a is an integer, and p is not a divisor of a, then p is a divisor of a^(p-1) - 1." However I don't completely understand how this is used. I can see how you can take a number, then find another number that has the original number as a factor, but I do not understand how it is used to take a number and find its factors. Can you help me out?

Doctor Rob answered:

Thanks for writing to Ask Dr. Math, Gabriel. There are two separate ideas here. One is the factoring method, so far unspecified. The other is the theorem that you quote, which is known asFermat's Little Theorem. They are related in only an indirect way. Fermat's Little Theorem is used as atest of compositeness, as follows. You have a number p that you suspect may be prime, but don't know. You pick a number a which is relatively prime to p, that is, has no common factor with p. You compute the remainder when a^(p-1) - 1 is divided by p. If this is not 0, then the contrapositive of the theorem tells you that p is *not* prime after all, but is composite. If the remainder *is* 0, you aren't sure whether or not p is prime, but there is an excellent chance that it is. Now if you are faced with a number to factor, you may want to apply the above test.If it is composite, you will go ahead and try to factor it.If it is most likely prime, you wouldn't waste any work trying to factor it without first trying to prove that it is prime, which is much more likely. There certainly is no point trying to factor prime numbers.

We saw this a couple weeks ago.

Fermat devised two factoring algorithmsthat I know about. The one with which his name is usually associated goes like this. Start with N, the composite number to be factored. Let a be thebiggest integer with a^2 < N. Write down the following table: k a+k a-k GCD(a+k,N) GCD(a-k,N) 0 1 2 3 4 etc. and fill in the blanks in the table. If any of the GCD's are greater than 1, you have found a factor of N. For example, if one tries to factor1037by this method, you'll start with a = 32, k 32+k 32-k GCD(32+k,1037) GCD(32-k,1037) 0 32 32 1 1 1 33 31 1 1 2 34 30 17 so 1037 = 17*61.

Here, he used \(a=32\) because \(32^2=1024<1037\), then looked for a nearby number that has a common factor with the given \(N=1037\). When such a number is found, that common factor is what we’re looking for.

The idea here is to start looking for factors assuming a pair of similarly large factors, rather than a small prime. If a pair of factors are close together, then they will be close to the square root; so we start our search there. So this is a sort of “hopeful guess” strategy.

But how do you find the **GCD** without already knowing factors? You use the Euclidean algorithm for the GCD, which just uses division and remainders. In this case, to find \(GCD(34,1037)\), we do this:

$$1037\div34=30\text{ R}17\\34\div17=2\text{ R }0$$ Since the GCD is 17, not 1, we have found a factor: 17.

The other method is called theDifference of Squares Method. The general idea is to write N = a^2 - b^2 = (a+b)(a-b). If you can find a and b which makes this true (aside from b = (N-1)/2, a = (N+1)/2, which aren't helpful), then you have factored N. Fermat did this by rewriting the equation in the form a^2 - N = b^2. Then he started with thesmallest positive a with a^2 >= N. If a^2 - N is a perfect square, then that a and b = sqrt(a^2-N) will work. If it is not a perfect square, then up a by 1 and try again. The work is made easier if, instead of squaring (a+1) and then subtracting N from that, you simplyadd 2a + 1 to the previous value, because (a+1)^2-N = (a^2-N)+2a+1. For example, if one tries to factorN = 1037by this method, you'll start with a = 33, and the work will look like this: a a^2 - N 2a + 1 33 52 67 52 + 67 = 119 34 119 69 119 + 69 = 188 35 188 71 etc. 36 259 73 37 332 75 38 407 77 39 484 = 22^2 so 1037 = 39^2 - 22^2 = 61*17. You see that neither of these methods is related to Fermat's Little Theorem.

This method is sometimes just called Fermat’s Factorization Method; while it can be slow when there are small factors, it is useful after an attempt at trial division, which will catch that case.

Here, you need some way to take approximate square roots, whether a calculator or one of the available manual algorithms. Testing the root obtained to the nearest whole number will show that it is exact.

Another question, from 2003, will give us four methods, all demonstrated for 1189:

Factoring Very Large Numbers into Primes Suppose I have areally big numberto be factored into primes. What is the best possible way of doing it? I know I can divide by increasing primes, but that gets very hard for monstrous numbers. Is it possible to find them in any other way?

Doctor Rob answered:

Thanks for writing to Ask Dr. Math, Chetan! There are a number of ways to approach finding prime factors of large natural numbers. I will discuss several, including some that are based in a field of mathematics called modular arithmetic. The one you know, where you divide successively by 2, 3, 5, 7, 11, 13, 17, 19, 23, ..., the prime numbers in order, is calledTrial Division. It is very effective for numbers up to about 1000 when doing the divisions by hand, and to about 1,000,000 when using a computer. The worst-case time to factor a composite N is sqrt(N) divisions. The smallest prime factor is always found first.

For more than a million, you would need to have, and use, a list of primes through 1000.

An old-fashioned way which is often effective is to express N as the difference of two squares, that is, to find x and y such that N = x^2 - y^2 = (x - y)*(x + y). One way to do this is tostart with x being the integer just larger than sqrt(N), and see if x^2 - N is or is not a perfect square. If it is, you have found y^2. If it is not, replace x by x + 1, and try again. There are someshortcutswhich you'll soon discover, since (for example) perfect squares must end in 00, n1, n4, 25, m6, or n9, where n is an even digit and m is an odd one. Even better, one can eliminate whole congruence classes of possible values of x by reducing the equation modulo a small prime, and using the fact that both x^2 and y^2 must bequadratic residuesmodulo that prime. For example, supposeN = 1189. Then start with x = 35, x^2 - N = 1225 - 1189 = 36 = 6^2. We've been lucky and got a success on the very first value of x! Then N = (35 - 6)*(35 + 6) = 29*41.

After this, of course, you would see if you can factor either of the factors just found.

In the version we saw before, we used a shortcut by adding \(2x+1\) to \(x^2\), rather than doing the harder work of directly calculating \((x+1)^2\). Here, some new shortcuts are mentioned, though we didn’t have to use them: Only check if the newly found *y* is a square when the last two digits make that possible. In the earlier example, half of the numbers would have been excluded, saving the work of finding square roots.

The following method is attributed to Euler:

Another interesting way is to express N as theSUM of two squares in two different ways: N = a^2 + b^2 = c^2 + d^2, 0 < a < c < d < b. This can only work if N = 1 (mod 4). Then N = ((bc + ad)(bc - ad))/((b + d)(b - d)). The factors in the denominator willcancelwith some in the numerator, but what is left will still be a useful factorization of N into two parts.

Not all numbers can be written this way, of course; but if it can be done, then this method can be faster than Fermat for numbers whose factors are not close together. We find that $$a^2+b^2=c^2+d^2\Rightarrow b^2-d^2=c^2-a^2$$ and $$\frac{(bc+ad)(bc-ad)}{(b+d)(b-d)}=\frac{b^2c^2-a^2d^2}{b^2-d^2}\\=\frac{b^2c^2-c^2d^2+c^2d^2-a^2d^2}{b^2-d^2}\\=\frac{b^2c^2-c^2d^2}{b^2-d^2}+\frac{c^2d^2-a^2d^2}{b^2-d^2}\\=\frac{(b^2-d^2)c^2}{b^2-d^2}+\frac{(c^2-a^2)d^2}{c^2-a^2}\\=c^2+d^2=N$$

This is not written as a single product, because factors need to be rearranged to obtain a pair of integers.Â For example:

Again, ifN = 1189, one can find 1189 = 10^2 + 33^2 = 17^2 + 30^2, so N = (33*17 + 30*10)*(33*17 - 30*10)/(33 + 30)*(33 - 30), = (561 + 300)*(561 - 300)/(63*3), = 861*261/(3^3*7), = (861/21)*(261/9), = 41*29. This can be generalized to writing N = a^2 + k*b^2 = c^2 + k*d^2, 0 < a < c, 0 < d < b. There are always values of k which can be used, no matter whether N = 1 (mod 4) or N = 3 (mod 4). Then N can be factored in the same way as above.

For slightly larger numbers, I would try the Pollard Rho Method. It goes like this. For factor N, start with x(0) as any convenient number except 0, 1, or -1, and for each n > 0, compute x(2n - 1) = x(2n - 2)^2 - 1 (mod N), x(2n) = x(2n - 1)^2 - 1 (mod N), d(n) = GCD[N, |x(2n) - x(n)|]. Continue this until you find a d(n) with 1 < d(n) < N. Then d(n) is a factor of N, which is then split into two smaller factors d(n) and N/d(n). The worst-case time to factor a composite N is N^(1/4) steps. Small factors tend to be found before large ones, but not necessarily!

What we are doing here is simply making a sequence recursively defined by $$x_n=x_{n-1}^2-1\text{ (mod }N)$$ and comparing a pair of terms, one moving twice as fast as the other, \(|x_{2n}-x_n|\). As in the first method above, we would use the efficient algorithm for finding the GCD.

Again, ifN = 1189, this proceeds as follows. Let x(0) = 4. n x(2n-1) x(2n) |x(2n) - x(n)| d(n) 0 4 1 15 224 209 1 2 237 285 61 1 3 372 459 222 1 4 227 401 116 29 Thus N = 29*41.

I initially misinterpreted the method, in part due to a typo I have corrected here, and because the fourth column is not what you might expect. I have added color to show what pairs of numbers are subtracted at each step. We can see this more clearly if we write the sequence \(x_n\) in a single row:

Although there is much more that could be said about why the method works, and why it is efficient, you might naÃ¯vely see it just as a way to randomly choose numbers with which to find the GCD; whenever this turns out to be greater than 1, we have a divisor! (Occasionally it will fail, and you need to pick a different starting number. There are several ways to vary the method.)

This method is discussed a little differently in

Factoring Large Numbers

Another possibility is the Pollard P-1 method. To factor N, start with x(1) = a, for some convenient integer a > 1, and for each n > 1, compute x(n) = x(n - 1)^n (mod N), d(n) = GCD[N, x(n) - 1]. Continue this until you find a d(n) with 1 < d(n) < N. Then d(n) is a factor of N, which is then split into two smaller factors d(n) and N/d(n). The worst-case time to factor a composite N is about sqrt(N) steps, but the average time for a random N is much smaller. Small factors tend to be found before large ones, but not necessarily! Again, letN = 1189. Pick a = 2. Then n x(n) d(n) 1 2 1 2 4 1 3 64 1 4 426 1 5 575 41 So N = 41*29.

Here we are raising \(x_n\) at each step to a higher power to get the next (all modulo *N*). In particular, \(x_n\equiv a^{1\cdot2\cdot3\cdots n}\).

We are searching for a prime factor *p*, which turns out in this example to be \(p=41\). We found it at the fifth step because \(p-1=40=2^3\cdot5\), whose largest prime factor is 5; we see that $$x_5=2^{1\cdot2\cdot3\cdot4\cdot5}=2^{120},$$ so this is the first time the exponent had 5 as a factor, and thus could be a multiple of \(p-1\). (This is why we raise to increasing powers. A fuller form of the method multiplies by successive primes.)

By Fermat’s Little Theorem, \(2^{p-1}\equiv1\text{ (mod }p)\), so that \(\left(2^{p-1}\right)^{k}\equiv1\text{ (mod }p)\) for any positive integer *k*; in particular, $$2^{120}=\left(2^{40}\right)^{3}=\left(2^{p-1}\right)^{3}\equiv1\text{ (mod }41),$$ and therefore $$2^{120}-1\equiv0\text{ (mod }41),$$ so that \(x_5\) is a multiple of the prime 41. And since 41 is also a factor of our modulus, \(N=1189\), we could successfully discover this as a GCD.

Note that this method will not always work at all; it assumes that \(p-1\) has a reasonably small factor. But when it does work, it can be very effective.

For really big numbers (scores of digits), the methods of choice are two very complicated methods called theElliptic Curve Methodand theNumber Field Sieve. Explaining them is more than I can do in this message. There are many other methods, too, which are effective in some circumstances. Some of their names areFermat's Method, theContinued Fraction Method, andSQUFOF, among many others. In any case, once you have split N into two factors, you should test the factors to see if either or both is composite. If so, one should continue by trying to factor these smaller composite numbers using an appropriate method such as those above. Compositeness testing is another whole problem!

For some of theseÂ methods, as well as those we’ve touched on, see MathWorld here.

Just for fun, having made a spreadsheet that carries out each of these methods (with manual steps in some cases), I put in the number 838,861 that we had to factor for the first question.

The **Fermat search starting at the square root** didn’t find anything until \(k=121\), at which point I tested \(a-k=794\) and found the GCD 397. It took so long because each prime factor, 397 and 2113, is far from the square root, 915. If they had been closer, we would have found one sooner.

The **Fermat difference of squares** method likewise took a long time; I had to increase *a* from 916 all the way to 1255, so that $$a^2-N=1255^2-838,861=736,164,$$ and \(b=\sqrt{736,164}=858\). Then $$a-b=1255-858=397\\a+b=1255+858=2113.$$

The **sums of squares** method required decreasing A from 915 to 819, so that \(B=410\) and the fraction became $$\frac{686,725\times25,805}{1625\times13};$$ moving factors around, this became $$\frac{686,725}{325}\times\frac{25,805}{65}=2113\times397.$$

The **Pollard rho** method worked quickly. Starting with \(x_0=2\), after 8 terms I got $$x_8-x_4=472,825-3968=468,857,$$ and the GCD was 397.

For the **Pollard \(p-1\)** method, I had to try values of *a* from 2 through 34, but that one worked quickly; $$x_3=461,315,$$ and the GCD was 397.

I would not want to have done this entirely by hand! But then, I also would not want to have tried dividing by all the primes from 2 to 915 (though I did list them all a couple weeks ago).

]]>

We’ll start with this question from 1997:

Prime Factorization The other day while I was gone, my class learned about prime factors. Now we have a homework sheet that says "Write the prime factorization for each number". I don't know what it means. Could you please help me?

Doctor Wallace answered first:

Hi Jayme! Let's begin with some definitions. Afactoris an integer that exactly divides a given integer. For example, if we are given the number 12, we can list its factors as the following: 1, 2, 3, 4, 6, and 12. This is because each of these numbers goes into 12 evenly, with no remainder. Notice that 5, for example, is not listed, because 12 divided by 5 leaves a remainder. Now, aprime numberis one that has only 2 factors: 1 and itself. For example, 7 is a prime number, because if we list out all its factors, we only have 1 and 7 on the list. No other number divides into 7 without leaving a remainder.

Those are the words; what about the phrase?

Now, we can combine these two ideas and ask about theprime factors of a number. For example, what are the prime factors of 12? Answer: 2 and 3. (We can also include 1, but since it is a factor of every number, it is usually omitted from such lists.) These are the only two prime numbers in the list of the factors of 12, so they are 12's prime factors.

We see here why 1 is not considered as a prime, even though it once was. It just complicates things that are already complicated enough!

Now for your homework. It asks you to write the "prime factorization" of a number. That's just a little different from writing a number's prime factors. It's important that you understand this. We listed 2 and 3 as the prime factors of 12, but they are NOT the prime factorization of 12. The two ideas are different.

Prime factors are just a list; we want something more.

So what isprime factorization? Well, there is a theorem in mathematics that says that any integer can beexpressed as the product of its prime factors. This means that we can write a number using only the product of its prime factors, and we areallowed to repeat some of themif we need to. Let's look at an example. Let's take our friend12. We've already seen that theprime factors of 12 are 2 and 3. So how can we write 12 as a product of these factors? Well, 2 x 3 = 6. If we multiply 6 by 2, we'll get 12. So12 can be written as 2 x 2 x 3. This is called the prime factorization of 12. (The numbers could be written in any order, but usually we write the smaller ones first, and then go to the bigger.)

Putting the smaller prime factors first is not *required*, but is a common *preference*; this way, there is only one way to write it, making it easier for teachers to check! We could also write it using exponents:

$$12=2\times2\times3=2^2\times3$$

Let's do another one. How about10? The prime factors of 10 are 2 and 5. Since 2 x 5 = 10, the prime factorization of 10 is 2 x 5.

$$10=2\times5$$

I don't know what kinds of numbers are on your homework sheet. If they aresmall numbers, like these in my examples, you should be able to figure them out without too much trouble. Just remember that in the prime factorization, you can only use prime numbers, and they must be factors of the number you're trying to find the prime factorization for. You may use any of the number's prime factors as many times as you like. And you know what else?Each number has only one prime factorization. Finding it is a little like a puzzle.

This is called the **Fundamental Theorem of Arithmetic**, or the **Unique Factorization Theorem**. (It really applies only to all integers *greater than 1*, since 1 is not a prime.)

Suppose you havelarger numbers. For example, how would you find the prime factorization of126? Well, one way you could start would be by noticing that 126 is even. 2 is the only even prime number, and it divides evenly into every even number. So, if we divide 126 by 2 we get 63. We know from our multiplication tables that 63 = 9 x 7. We know that 7 is prime; what about 9? Nine is not prime: 9 = 3 x 3. So now we can stop since we have reached only prime numbers. So the prime factorization of 126 is: 126 = 2 x 3 x 3 x 7 = 2 x 9 x 7 = 2 x 63 = 126

We found one prime factor at a time, first the 2, then the 7, then the 3’s: $$126=2\times3^2\times7.$$ We’ll see more examples as we go.

I hope that makes it easier to see. If you start with an odd number, you canguess what might go into it, until you find a factor. Try prime numbers, of course, like 3, 5, 7, 11, and 13. When you find one that works, then divide it into your number, andrepeat the process with the new, smaller numberyou get, just as we did above.

Then Doctor Mitteldorf joined in, four days later, with a slightly different perspective:

Dear Jayme, When youfactor a number, you're justfinding some numbersthat can be multiplied together to make that number. You can factor 24 by saying 6*4 or you could just as well say 12*2 or 8*3.Prime factorizationis when youfinish the processby breaking down each of your factor numbers, and keep going until you get to numbers that aren't divisible by any others (except, of course, 1 or the number itself).

This is a different approach than Doctor Wallace’s one-prime-at-a-time style; as we’ll see later, this can be expressed as a “tree”. We break the number into parts, and then break each of those into smaller parts, until we can’t go any further.

For example, if you said24 was 6*4, you might change the 6 to 3*2 and the 4 to 2*2, and you'd have 24 = 3*2*2*2. If you said24 was 8*3, you'd break down the 8 into 2*2*2, and you'd end up with the same thing as before: 24 = 3*2*2*2. (The order of the numbers doesn't matter.)

We’ll see this drawn as a tree below.

A 1996 question focuses on the process:

Write Numbers as Products of Prime Factors I need to write 4, 6, 8, 10, 12, and 14 asproducts of their prime factors. Please help! My mind is a blank.

Doctor Jaime answered, using one of these as an example, and then a slightly larger one:

Recall thatprime numbersare divisible only by themselves and one. Examples are: 2, 3, 5, 7, 11, 13, etc. The prime factors you need are prime numbers such that their product is the given number. So you need to do two things: 1.find the prime numbersthat are factors of the given number; 2. write the given number as aproduct of the prime factorsfound. To obtain the prime factors you just have todivide the given number by the prime numbersand see which divide the given number (with zero remainder). You begin by using the smaller prime numbers, because they are easier, to see which ones divide your number. When you find a prime number that divides your number, you get a certain quotient and you thenbegin the same process with the quotient.

For example, let's try this with number12. We begin with the smallest prime number: 2. 12 divided by 2 gives 6 as a quotient and zero as a remainder. So 2 divides 12, and we can say that12 = 2 x 6. We have now written 12 as a product of two numbers, 2 and 6, but they are not both prime factors. 2 is a prime number, but 6 is not. Therefore, we now need to write 6 as a product of prime factors.Again we begin with the smallest prime number: 2. 6 divided by 2 gives 3 as a quotient and zero as a remainder. So 2 divides 6, and we can say that6 = 2 x 3. The divisions end here because the quotient obtained, 3, is a prime number (it can only be divided by itself and give quotient 1). Now, how do we write 12 as a product of its prime factors (2 and 3 in this case)? Above we have obtained 12 = 2 x 6 = 2(2 x 3) = 2^2 x 3, (where 2^2 means 2 squared or 2 raised to the second power). So it must be:12 = 2^2 x 3

We just pulled out one prime at a time, and put them together to show the product; we can do this as a stack of divisions:

$$\begin{array}{rrr}{3}\\2\overline{\big)6}\\2\overline{\big)12}\end{array}$$ $$12=2^2\times3$$

Let's try again with number45, for example. We begin with the smallest prime number: 2. 45 divided by 2 doesnotgive zero as a remainder, so we must move to the next prime number, 3. 45 divided by 3 gives 15 as a quotient and zero as a remainder, so 3 divides 45, and we can say that45 = 3 x 15. 15 divided by 3 gives 5 as a quotient and zero as a remainder. So 3 divides 15, and we can say that15 = 3 x 5. The divisions end here because the quotient obtained, 5, is a prime number. So 3 and 5 are the only prime factors of 45. Now, how do we write 45 as a product of its prime factors (3 and 5 in this case)? Above we have obtained 45 = 3 x 15 = 3 * (3*5) = 3^2 * 5. So it must be:45 = 3^2 * 5You can again verify that it is really so, doing the calculation.

$$\begin{array}{rrr}{5}\\3\overline{\big)15}\\3\overline{\big)45}\end{array}$$ $$45=3^2\times5$$

Another method to find the prime factors is to use the so-called "factor trees." Youfind factorsof your number, and thenfactors of these factors, etc., until you arrive at prime numbers. For example, if you want to factor24, you may know that 24 = 6 x 4. But 6 = 2 x 3 and 4 = 2 x 2, and all the factors are prime. You can write this as a "tree": 24 / \ 6 4 / \ / \ 2 3 2 2 So the prime factors are 2 and 3. But 2 shows up three times and 3 shows up once, so: 24 = 2^3 x 3

I describe this approach as “opportunistic”: we happen to see a product, whether it involves a prime or not, and continue from there. The “leaves” of the tree (at the ends) are the primes.

As Doctor Mitteldorf mentioned above, we could also have done this with a different starting point:

24 / \ 8 3 / \ 2 4 / \ 2 2

Again, this leads to \(24=2^3\times3\).

For more on that last idea, see this 1998 question:

Making a Factor Tree How do you make afactor tree? I know what one is but my teacher gave us a quiz and I didn't know how to do it.

Doctor Mike answered with a bigger example:

Dear Kelsy, There are several ways to write these things down, and I will show you one. That will give you the idea. Here's an example. Let's say you want to factor630. Because there is a zero on the endyou know it has 10 as a factor. It can be written 63 * 10. Both of these factors can be factored further.Ten is 5*2and that's all.63 is 9*7, which gives the prime 7 and also9 which is 3*3. We can show all of this in a "tree" drawing like this. 630 / \ / \ / \ 63 10 / \ / \ / \ / \ 9 7 5 2 / \ / \ 3 3

Again, he started with an “obvious” pair of factors, and continued from there.

All of the numbers at the bottom (theleaveson the tree) areprime numbers, so you are done. To write out the factorization in an equation, you multiply all of them like this:630 = 3*3*7*5*2. Sometimes teachers want them written inincreasing orderlike this:630 = 2*3*3*5*7.

Or, as we’ve seen, we can write it using exponents: $$630=2\times3^2\times5\times7$$ You should do it whichever way is recommended in your classroom, or otherwise whatever way you like!

Sometimes people write the original number 630 on the bottom and have the connecting lines go upwards, so the "leaves" will be on top. Whether you draw trees or not, the basic idea is that tofactor a number completely, you first have to start somewhere, the way I started with 630 = 63*10.You could have started differently.You could have started by noticing that 630 is even and written down 630 = 2*315. That's fine. No matter how you start, you have to keep on until everything is factored completely into primes.

The important thing is that, regardless of the order, you will get the same result.

Here is a 2001 question, from a student who knew only about factor trees, and didn’t like them:

Prime Factors as Bricks I have trouble with prime factorization. I need an easier way to do it than making a tree.

After a preliminary answer with a reference to divisibility rules (which help to decide whether to bother to divide by certain small numbers), I tried:

Hi, Andre. Let's try taking the most basic approach I can think of, to see what this is all about. The prime numbers are the building blocks of which any whole number can be built by multiplying them together. Think of them as bricks. Some buildings might consist of a single brick (weird, but possible); most will be built of a number of bricks. Some of those bricks might be different sizes or colors, others might be identical. Suppose we want tobreak a building down into a pile of bricks, to see what it is made of. How do we do it? One brick at a time. That's what we want to do with numbers: tobreak them down by pulling out one brick (prime factor) at a time and putting them in piles.

We are going to take a brick wall,

and turn it into a neat pile of bricks,

So let's take the number245. There are two main ways to find the factors. One is to methodically go throughall the possible prime factorsand see if they are there. So we get a list of small primes to try: 2, 3, 5, 7, 11, ... Try one at a time, starting at the beginning of the list. Is there a2in this number? Divide by 2, and you find that it doesn't divide evenly. How about3? Again, it doesn't go in. (This is where knowing those divisibility rules can save time, but you can just do the divisions if you prefer not to take the time to learn them.) Now wetry 5: ___49_ 5 ) 245 It goes evenly, so we know that245 = 5 * 49We've pulled one brick out of the wall, and what's left of the wall is 49.

You may immediately recognize what sort of number 49 is; but you don’t need to. (Go ahead and use it if you do!)

Now we can see what prime factors there are in 49. We firstcheck whether there is another 5in there; taking one out doesn't mean there isn't another! (On the other hand, we knew we didn't have to try 3 again, because we know there weren't any there.) But 49 is not divisible by 5, so we continue through our list of primes. Is 49 divisible by 7? Yes, and the quotient is another 7: 49 = 7 * 7 so245 = 5 * 7 * 7Since we know 7 is a prime, we're finished; we have a pile of prime "bricks." The only thing left to do, if we want, is to pile up identical bricks by combining groups of the same prime as powers: 245 = 5 * 7^2 That's it!

Each time a division **fails**, we’ve learned something about the number that won’t change as we proceed; each time we **succeed**, we add a prime to our product, but don’t know whether there is another there until we try again.

The other approach is the opportunistic method: rather than go through the primes in order, we oftensee an obvious prime to pick first. (That's like seeing a loose brick sticking out and pulling that one out first, rather than starting at the top.) In this case, since 245 ends with 5, we can tell immediately that it isdivisible by 5, so we would divide by that first. Then when we see 49, we should recognize that as asquare, and can just write it that way. All that comes with experience. If you just want to take the slow route and make sure you get the job done, that's fine. The important thing is that you are getting to know how numbers are built.

Sometimes, the obvious factor is *not* a prime, as if a chunk of bricks fell out of the wall, ready to break apart. That’s really all the tree method does!

Andre replied:

Thanks, that was much simpler.

The tree may be *faster*; but first you have to *understand*.

I include this 1997 question because, although the answer starts with the Fermat test, it goes a little deeper than last time, then moves beyond. It comes from Dave, who is working on a computer program:

Large Prime Numbers I believe that I read somewhere (Ivars Peterson, I think) that it is possible todetermine if a very large number is prime using a simple procedure. (But not to determine its factors). It didn't say how this is done. If this is true, what is the algorithm?

Doctor Rob answered:

The situation is a bit more complicated than you remember. The fact is thatthe simple procedure does not provide a proof of primality, but may provide a proof of compositeness. It is based onFermat's Little Theorem, which says: Theorem: If p is a prime number, a is an integer, and p is not a divisor of a, then p is a divisor of a^(p-1) - 1. Given a number N we want to test, pick any old a, and find thegreatest common divisorof a and N, GCD(a,N). If this is not 1, then it is a factor of N, and N is composite. If it is 1, then compute the remainder r of a^(N-1) when divided by N. If r is not 1, then by Fermat's Little Theorem, N cannot be prime, so is composite. This gives theproof of compositeness. By the way, you might as wellchoose 1 < a < N-1, since a and a-N will give the same value of r, and since a = 1 or N-1 will always give r = 1.

This is a slightly different form of the method than we saw last time, but is equivalent. We are testing whether a given number *N* is prime, so we put it in the role of *p* in the theorem. By choosing a divisor *a* that is less than *N*, we know that *N* does not divide *a*. The theorem says that if *N* is a prime, then it must divide \(a^{N-1}-1\), which implies that \(a^{N-1}\equiv1\), so the remainder from that division must be 1. If the remainder is **not** 1, then, *N* **can’t** be a prime.

How to compute the remainder r?If N is even moderately large, computing a^(N-1) and then dividing by N will be a bad idea, since the number a^(N-1) will have many, many digits. The trick is to divide by N and keep only the remainder at all intermediate steps. It may not be obvious that this works, but it does. IfN = 67, N-1 = 66, you might compute a^66 by doing65 multiplications. After each one, divide by 67 and keep only the remainder. Better than doing a^66 by 65 multiplications (and 65 divisions by N), you can shortcut the computation by the following trick: a^66 = (a^33)^2, a^33 = a*a^32, a^32 = (a^16)^2, a^16 = (a^8)^2,a^8 = (a^4)^2, a^4 = (a^2)^2, a^2 = a*a. Working from the last equation backwards, you will need only7 multiplications(and7 divisionsby N).

This second way is equivalent to what I demonstrated last time for \(N=55,409,243\).

Let’s carry out this version of the method in full for \(N=67\) (though of course the Fermat test isn’t needed for such a small number):

Taking \(a=2\), we need to calculate \(a^{N-1}=2^{66}\text{ mod } 67\). This requires calculating, successively, \(2^1\),\(2^2\),\(2^4\),\(2^8\),\(2^{16}\),\(2^{33}=2^{32}\cdot2\),\(2^{66}\), all mod 67 (that is, finding the remainder at each step). These are: $$2^1=2\\2^2=4\\2^4=(2^2)^2=4^2=16\\2^8=(2^4)^2=16^2=256\equiv55\\2^{16}=(2^8)^2\equiv55^2=3025\equiv10\\2^{33}=(2^{16})^2\cdot2\equiv10^2\cdot2=200\equiv66\\2^{66}=(2^{33})^2\equiv66^2=4356\equiv1$$

This tells us that 67 *could* be prime. If we want more assurance, we could repeat, using 3 as the base: $$3^1=3\\3^2=9\\3^4=(3^2)^2=9^2=81\equiv14\\3^8=(3^4)^2\equiv14^2=196\equiv62\\3^{16}=(3^8)^2\equiv62^2=3844\equiv25\\3^{33}=(3^{16})^2\cdot3\equiv25^2\cdot3=1875\equiv66\\3^{66}=(3^{33})^2\equiv66^2=4356\equiv1$$

There are several variations of this calculation of **modular exponentiation by squaring**; a particularly efficient method given in Wikipedia is what I did last time.

If r = 1, then what can we say?All prime numbers will give r = 1, but there are a few composite numbers which will do so, too. For example, if a = 2, N = 341 = 11*31 is composite, but r = 1. Such N's are calledFermat pseudoprimeswith respect to base a. 341 is a Fermat pseudoprime with respect to base 2. It turns out that Fermat pseudoprimes with respect to any fixed base are uncommon. The chance of picking one at random from some large set of N's is very small. Thus, in some sense, which is again a complicated matter, if you get r = 1,N is "probably" prime.

In our example, we already know by trial division that 67 is certainly a prime; for a larger number, certainty would be much harder to attain, so knowing that a given number is *probably* a prime would be worthwhile, even though it might (rarely) be a pseudoprime.

A tactic you could use if you get r = 1 is topick another base aand repeat the calculation. If you get r = 1 again, try still another a. Continue this until you either find a proof that N is composite, or you decide that you couldn't possibly be unlucky enough to have an N which is a Fermat pseudoprime to all the bases you used. Then declare the number to be prime, andyou will be wrong only rarely. A flaw with the above tactic is that there exist numbers calledCarmichael numbers, for which, for all bases a such that N passes the GCD test, r will equal 1. The smallest one is 561 = 3*11*17. Every base a not divisible by 3, 11, or 17 will give r = 1. These are evenrarer than Fermat pseudoprimeswith respect to a given base a, but there are known to be infinitely many. If you happened to choose one of these, you might try very many bases, getting r = 1 over and over, then declare the number prime, and be wrong.

So absolute certainty by this method alone is impossible; but we can come close.

There are variations of the above method which get rid of the last flaw, give youproofs of compositeness, but onlyprobabilistic statements about primality. If you need to know more about them, write again. If you want a trueproof of primality, there are more complicated methods which will do this, but I am quite sure the above is what you remember reading about. The complicated methods can be proven to run on a computer in a relatively short time, and produce a certificate of primality which can be checked even faster.They could not, however, be termed "simple"in most senses of the word!

After some additional discussion about Dave’s programming project, Doctor Rob added a way to be *certain* for numbers with up to ten digits:

Here is another idea. Since your range is only up to 10^10 (as opposed to 10^1000[!!]), here is an alternative. Use theStrong Compositeness Test(below) with bases 2, 3, 5, and 7. If it fails all of these, and is not equal to 3215031751, then it is prime. The Strong Compositeness Test with Base a: To test a number N for compositeness: 1. If GCD(a,N) > 1, stop and declare that N is composite. 2. WriteN - 1 = 2^s*d, where d is odd. 3. Compute R, theremainder of a^d when divided by N. (Do this as described in the last message.) 4. If R = 1, stop and declarefailure. 5. For i = 0, 1, ..., s-1, do the following: a. If R = N-1, stop and declarefailure. b. Replace R with theremainder of R^2 when divided by N. c. If R = 1, stop and declare that N iscomposite. 6. Stop and declare Ncomposite.

Note that he is calling this a test for **compositeness** (which makes sense, as it doesn’t prove primality), so that “failure” means you haven’t proved it’s composite – it’s a likely **prime**. Other sources call that “success”!

A number which fails the Strong Compositeness Test with Base a, yet is composite, is called a "strong pseudoprimewith respect to base a." Every strong pseudoprime is a Fermat pseudoprime to the same base, but the reverse is false. The smallest strong pseudoprime with respect to base 2 is 2047. Theorem: The only number less than 2.5*10^10 which is a strong pseudoprime with respect to bases 2, 3, 5, and 7, is 3,215,031,751.

So this test can be considered as **proof of primality** for any number less than 25 billion.

Let’s try it for our **prime** \(N=67\), with \(a=2\):

- First, since 67 is not even, we can use \(a=2\).
- Now we write \(N-1=66\) as \(2^1\cdot33\), so \(s=1\) and \(d=33\).
- Now we compute the remainder of \(2^{33}\) mod 67; from our work above, it is \(R=66\).
- This is not 1, so we do step 5, for
*i*from 0 to \(s-1=1-1=0\) (that is, we do it only once). - We find that \(R=66=67-1=N-1\), so we have “failed”: 67 is
**not**proved to be composite. It**is (potentially) prime**.

Repeating with a different divisor *a* would confirm this.

To see what happens when the number is **composite**, let’s try again, with \(N=221\).

- Again, we safely choose \(a=2\).
- We write \(N-1=220\) as \(2^2\cdot55\), so \(s=2\) and \(d=55\).
- Now we compute the remainder of \(2^{55}\) mod 221; I get \(R=128\).
- Now we repeat step 5, for
*i*from 0 to \(s-1=2-1=1\) (that is, twice). - First time: \(R\ne N-1=220\), so we continue. We find that $$R^2=128^2=16,384\equiv30\text{ (mod }221).$$ This is not 1, so we repeat with \(R=30\).

Second time: Since \(30\ne220\), we continue, finding that $$R^2=30^2=900\equiv16\text{ (mod }221).$$ This is not 1, so we drop off the end of the loop. - We report that 221
**is composite**.Â It is, in fact, \(13\times17\).

We’ll close with two **actual tests for primality** (not just compositeness).

Here is a question from Brian in 1994:

Testing primality of 32-bit numbers What is the best (fastest) way to test ifan arbitrary 32-bit numberis prime? Dividing by all numbers up to the square root is not great since you need to build a table of primes. I am using a test that checks if the number is astrong pseudoprimeto bases 2, 3, and 5 which is pretty good. Butis there a better way?

A 32-bit number can be as large as 4,294,967,295, so it’s within the range of that last method. BrianÂ evidently knows about Miller-Rabin. Doctor Ken answered:

Yes, there is a faster way. I'll assume that you're familiar with modulo arithmetic, since you wrote about strong pseudoprimes. If this isn't the case, let us know. The better way is called theLucas Test for Primality. It does rely on factoring, but not of the number in question. If you're trying to determine whether the number M is prime,you have to factor M-1. This isn't usually very hard, since it's certainly even if you're testing M for primality, and in general you'll get lots of small factors for a big number. Anyway, here's how you apply the test:

We’ll demonstrate this test, again, with the prime \(M=67\) and the composite \(M=221\). In each case, we first factor \(M-1\):

$$67-1=66=2\cdot3\cdot11$$ $$221-1=220=2^2\cdot5\cdot11$$

If you can’t do that for the number of interest (see an upcoming post on factoring large numbers), then you can’t use this test.

You findall the prime factorsp1, p2, p3, ..., pk that divide M-1. You don't really need to know how many powers of each prime go into M-1, just which primes. Then you pick a number (call it A) that's less than M. Raise A to the power M-1, and find what it's congruent to Mod M. If it'snot congruent to 1, then M isn't even a pseudoprime (which is different than a strong pseudoprime) to the base A, so it'scomposite. If A^(M-1) iscongruent to 1Mod M, thencontinue. Raise A to the power (M-1)/p1, and find what it's congruent to Mod M. ***Note: do you have an efficient way to raise numbers to big powers when you're doing modulo arithmetic? The number of steps you can do it in is about Log of the number of digits in the power. It's done most efficiently by the method of successive squares.*** If it's congruent to 1, pick a new A and try again. If it's not, then find A^((M-1)/p2) (Mod M). Keep going like thiswith all the different primes that divide M-1. What you want is for there to be a number A for whichnoneof these power-raisings is congruent to 1 Mod M. Stated precisely, here's the theorem: If there is an A such that A^(M-1) â‰¡ 1 (Mod M), and for every p dividing M-1 A^((M-1)/p) â‰¡Ì¸ 1 (Mod M), then M is prime.

The proof is beyond what I want to cover here.

I’ll start with \(A=2\) for both of our examples, so we can use previous work.

For \(M=67\), we have three prime factors, 2, 3, and 11.

First, we find that \(A^{M-1}=2^{66}\equiv1\text{ (mod 67)}\), so we proceed.

Taking our first prime factor, \(p_1=2\), we find that $$A^{\frac{M-1}{p_1}}=2^{\frac{66}{2}}=2^{33}=2^{32}\cdot2\equiv66.$$

We repeat for the second prime factor, \(p_2=3\), and find that $$A^{\frac{M-1}{p_2}}=2^{\frac{66}{3}}=2^{22}=2^{16+4+2}\equiv10\cdot16\cdot4=640\equiv37.$$

We repeat for the third prime factor, \(p_3=11\), and find that $$A^{\frac{M-1}{p_3}}=2^{\frac{66}{11}}=2^{6}=64.$$

None of these was 1, so we have **proved that 67 is prime**.

For \(M=221\), we have three prime factors, 2, 5, and 11.

First, we find that \(A^{M-1}=2^{220}\equiv16\not\equiv1\text{ (mod 221)}\), so we immediately conclude that it is **composite**.

Note that if we got 1, we would try another *A*, and another; in principle we might have to try every number, if it weren’t for the built-in compositeness test!

Note that this gives anairtight proof of the primality of a number. It's a little slower then finding out whether M is a strong pseudoprime to every base, which is what you'd really have to do to really show that your number is really a prime, and not just some imposter.

That’s what makes this “better” than Miller-Rabin. But, as we saw before, the latter is really sufficient:

But you know, it's really a pretty good test tocheck the first few bases for pseudoprimes, and here's why. If you find that M is astrong pseudoprimeto the base 2 and M is smaller than 2047, then M is prime. If you test it again with the base 3, and it's again a strong pseudoprime, then M is a prime provided it's less than 1373,653. If you test it again to the base 5, and it's again a strong pseudoprime, then M is prime provided it's less than 25,326,001. That's the smallest number that's a SSP to the base 2,3, & 5. Soodds are pretty good that if it tests out to all three bases, it's a prime. Of course, it's a gamble.....

So, experience with the compositeness tests allows us to have great confidence in them, even though they don’t give certainty for *extremely* large numbers.

We’ll close with a 2005 question:

Fastest Primality Test? Hello! I would like to ask about "the fastest prime test". I found an interesting article on the Internet which said, "We present adeterministic polynomial-time algorithmthat determines whether an input number n is prime or composite." It was from the Department of Computer Science and Engineering at the Indian Institute of Technology in Kanpur, India. I have some questions about it: 1. Is it reallyfasterthan the Rabin Miller or Lucas tests? 2. If it is true, why can't we use this form tosearchprime numbers with distributed algorithm? (e.g www.mersenne.org, Mersenne-Prime)? 3. The algorithm speed is O(log^12 N). What do you think about this algorithm? Could the mathematicians develop an algorithm about O(log N)?

Doctor Vogler answered:

Hi Norbert, Thanks for writing to Dr. Math. Those are very good questions. First of all, theRabin-Miller testis a pseudo-primality test, which means that if you give it a composite number, then it will _probably_ tell you that it is composite. But if you give it a prime number, then it will tell you that it is _probably prime_. A composite number that passes a pseudo-primality test is called a pseudoprime. It turns out thatit is not known whether there are any Rabin-Miller pseudoprimes, but no one has yet proven that there are none.

(I’m not sure about this, as sources mention strong pseudo-primes, which seem to be what he is referring to.)

There are other primality tests that aremore efficientthan the algorithm you just mentioned, in the sense that they finish more quickly on numbers that we've tried, butthey are _probabilistic_ algorithms, which means that some part of the algorithm is based on choosing a random number and then doing some computations with it. With a certain probability, it will tell you that your number is either prime or composite.In practice, after a few tries, you get a result.But many mathematicians wanted to find a_deterministic_ algorithm(one that isguaranteed to finish in no more than a known number of steps) which will (provably) finish in a number of steps that is a polynomial in log N. That is what this new algorithm does, and the creators proved that it would always finish inO((log N)^12)time. Later, someone else proved that it would, in fact, finish more quickly than that, in almost O((log N)^6) time. That still doesn't make it faster than other tests, though, just faster than other general-purpose deterministic primality tests.

This “big-O” notation describes, not the actual speed of an algorithm, but how that speed depends on the input – that is, how fast the time it takes grows when you put in bigger and bigger numbers. The “new” algorithm is not faster on average than other methods, but promises not to take as long as they *might*, and to *guarantee* a maximum.

TheLucas-Lehmerprimality test is adeterministicprimality test, but it isnot general-purposebecause itonly works on Mersenne numbers. It is much faster than other algorithms (such as the one you mentioned), but it only works for those special numbers. Consider that mersenne.org reports that the 42'nd Mersenne prime found was N = 2^25,964,951 - 1, which took 50 days on a 2.4 GHz computer, which is 50 days * 24 hours/day * 60 minutes/hour * 60 seconds/minute * 2,400,000,000 instructions/second = 10,368,000,000,000,000 instructions (or, more correctly, cycles, but the difference is not important). In this case, log N = 25,964,951 * log 2 = 17,997,532.58... and(log N)^12= 1,154,929,888,777,235,354,042,315,422,387,627,895,434, 164,939,766,318,268,467,306,355,354,201,088,395,258,493,601,391 which is a whole heck of a lot more than the number of instructions used in the Lucas-Lehmer test. In fact, (log N)^6 = 33,984,259,426,640,965,925,133,186,173,883,788,875,047,677 which is still a heck of a lot more. How many days would this many instructions take on that 2.4 GHz computer? How many trillions of years?

So Lucas-Lehmer, *when applicable*, is considerably faster than AKS.

For more on these and other tests, see MathWorld.

]]>

First, consider this 1995 question, which takes us back to some issues we dealt with last time in the broader context:

Finding Prime Numbers I am writing to you about a question I have about prime numbers. I know that by definition a prime number is a number that will not divide evenly into any number except for 1 and itself. I am currently working on a computer program in Turbo Pascal that finds prime numbers. I am doing this bydividing the number by every integer between 1 and itself-1. I would like to know if I would get the same exact answers if I were to test the numbers onlybetween 2 and the square rootof the number? For example if I was checking the number 100 (obviously 100 is composite, but I am just using it for simplicity), I would check every number between 2 and 10, inclusive, instead of checking every number starting at 2 and ending with 99. Would I get the same answer?This has been suggested to me by my math teacherbut I am not quite sure what he was saying and I can't ask him now because unfortunately he is in the hospital recovering from open-heart surgery.

Joe meant to say that a prime number is one that can’t be *divided evenly by* any number except for 1 and itself.

Doctor Eric answered with a brief explanation of the **square root** idea (which we saw from a different perspective last time, and will see explained more fully below), and also that we can use only **primes**:

Your teacher was right. In fact, there's an even more specific set of numbers that you can use, but let's first figure out what he meant.Why stop at the square root?Do you see how the square root kind of forms a middle point for divisors of the number? To get the desired number, you'd have to multiplyone number smaller than its square root, and one bigger. So to test numbers above the square root would be redundant! Now, what's even more interesting is that you don't even need to check every integer between 2 and the square root of the number. I propose that it suffices toonly check PRIME numbers between 2 and the square root. Can you figure out why? As far as the programming goes, this would involve somehow keeping track of the primes that you've found so far, and then only dividing your next test number by those in this list that are smaller than the square root of the number.

So the best version of this Trial Division Test is to list all the **primes** from 2 to the **square root** of our number, and do the divisions. Let’s see, for example, whether **197** is prime.

Its square root is a little bigger than 14. (You can see this with a calculator, or if you happen to know that \(15^2=225\), which is larger than 197.) So we list the primes less than 15, namely 2, 3, 5, 7, 11, 13.

Now we divide:

- \(197\div2=98.5\), not an integer, so we continue.
- \(197\div3=65.6\dots\), not an integer, so we continue.
- \(197\div5=39.4\), not an integer, so we continue.
- \(197\div7=28.1\dots\), not an integer, so we continue.
- \(197\div11=17.9\dots\), not an integer, so we continue.
- \(197\div13=15.1\dots\), not an integer, so it’s
**prime**.

How about **187**?

- \(187\div2=93.5\), not an integer, so we continue.
- \(187\div3=62.3\dots\), not an integer, so we continue.
- \(187\div5=37.4\), not an integer, so we continue.
- \(187\div7=26.7\dots\), not an integer, so we continue.
- \(187\div11=17\) exactly, so it’s
**composite**. (namely, \(187=11\times17\))

At several points we didn’t really have to divide, because we know, for example, that a number ending in an odd digit isn’t divisible by 2, and one not ending in 0 or 5 is not divisible by 5. These divisibility tests can save time; but only for certain small divisors. In general, you’d have to divide.

Of course, this method requires already having a list of primes up to some point; for instance, in order to test any number less than 10,000, we would need to know all the primes less than 100. For many purposes, that will be reasonable; but not for *really* big numbers.

Paul in 2001 wanted a fuller explanation for that part about the square root:

Determining Primes by Their Square Roots I have a bit of a math problem. It has to do with determining if a very large number is a prime. One method entailsdividing the number by every smaller prime number. If any divide into it, it's not a prime. This would be a big job if the number was something like 400 digits long. Another way I read about was to take the square root of the number andtest all the primes less than its square root. The explanation went like this: "When a number is divided by another number that is greater than its square root, the result is a number smaller than the square root. For example, the square root of36is 6. Dividing 36 by 2, a smaller number than 6, gives 18, a number that is larger than the square root. To prove that 37 is prime it is only necessary to divide it by primes less than 6, since if it had a prime factorgreater than 6, it would have to have oneless than 6as well." I understand the explanation, up to the last sentence. I fail to see the underlying logic.Why if a prime factor exists below the square does one have to exist above the square too?The number40can be divided by the prime 2, a number below its square root, but no other primes can do this above its square root. Have I missed something? What's the logic here?

The teacher’s example of 36 involves a smaller prime, 2, implying a larger divisor, 18 – but that isn’t prime. Paul’s example of 40 points out that in this case there is no prime divisor greater than the square root. The explanation is a little more subtle than the teacher said.

Doctor Rick answered:

Hi, Paul. You have the statement backward. It says thatif a prime factor exists that is GREATERthan the square root of the number, then there must be one LESS than the square root -notthatif a prime factor exists that is LESSthan the square root, there must be one GREATER. (Your example shows that the latter is not true.)

It’s easy to misread (or miswrite) this sort of logic!

A little algebra will start to clear things up:

Consider the number N = 174, which has a prime factor (M = 29) that isgreater than the square root of N(13.2). Since M is a factor of N, we know that N/M = 6 is also a factor of N. We know also that M > sqrt(N) 1/M < 1/sqrt(N) N/M < N/sqrt(N) N/M < sqrt(N) so we know that N has a factorless than the square root of N. This factor, N/M, might be a prime or a composite (in this example, it is composite, 6 = 2*3). If it is composite, however, we know that it has aprime factorthat is less than N/M, and therefore less than the square root of N. I have just proved that,ifa prime factor exists that isgreaterthan the square root of the number,thenthere must be onelessthan the square root of N.

In the example with \(N=174\), the other factor, \(174\div29=6\), is less than \(\sqrt{174}\approx13.2\); that is not itself a prime, but any prime factor of it will also be less than \(\sqrt{N}\). Not all numbers will have a factor greater than the square root; but if they do, there will also be a factor (and therefore a prime factor) less than the square root.

Why is this useful in finding primes (as opposed to the turned-around version)? We useproof by contradiction. We are seeking to find out whether N is prime. We have tested all primes less than the square root of N, and found that none is a factor of N. We can stop here, because we knowthere can be no prime factor of N that is greater than the square root of N. Why? Because,if there were, then there would also be a prime factor less than the square root of N, andwe have already found out that there is none.

The proof by contradiction supposes that there is a prime factor that we haven’t tried yet (that is, one greater than the square root), and show that that is impossible, because we would have to have found a prime factor smaller than the root.

In my example, N = 174, we plan to test all primes up to 13 (2, 3, 5, 7, 11, and 13). When we test for 2 and find that it divides 174, we are done: 174 is not a prime. In the text example, N = 37, we test all primes up to 5 (2, 3, and 5) and find that none divides 37. Therefore we know that 37 is prime without testing any larger primes. If 37 were divisible by a larger prime M, then 37/M would be a factor of 37, and37/M would have to be a product of the primes we have already tested. Does this explanation help you make sense of what you have read?

It did.

A 2004 question raises the same issues:

Determining If a Number is PrimeIs there a formula for finding if a number is prime?I've written a program that will tell you if a number is prime, but it is slow for larger numbers becauseit checks all numbers between 1 and the numberto see if they are factors of the larger number. As you can see, checking a number in the billions would result inbillions of divisions, which takes time. I've tried looking online, but haven't been able to find anything.

He could use the advice given above, if his numbers were only, say, in the millions; but for *really* big numbers, more would be needed.

Doctor Vogler answered:

Hi Daryl, Thanks for writing to Dr Math. There are several "formulas." They are called "primality tests." First there are the "pseudoprimality tests" which canquickly tell you if a number is NOT prime, but theycan not guarantee that a number IS prime. TheFermat testis the best-known of these. The trueprimality testsare more complicated (which is why you usually start by checking if the number is clearly composite first, with a pseudoprimality test) but they can tell you conclusively whether a number is prime. In fact, a recent discovery was a "polynomial-time deterministic primality test" which means that it is "fast" by a particular technical definition of "fast." Other non-deterministic algorithms are more effective or more efficient, but this one is interesting theory. For precise descriptions of particular primality tests, search Google for "primality test." See also the account on MathWorld at Primality Test http://mathworld.wolfram.com/PrimalityTest.html

That page links to descriptions of several tests, some of which we’ll look at next week.

Now let’s look at the Fermat test.

Here is a similar 1998 question:

Primality TestingIs there any formula to find if a number is a prime?For example, is there a formula to find out if 1642749328584902 is a prime number? Matthew

Doctor Wilkinson first pointed out the obvious:

An excellent question! Of courseyour example is not prime, because it ends in 2 and all numbers that end in 2 are divisible by 2. There is nosimpleway to check whether a number is prime, butthere are methods that work much better for large numbers than just trying all possible divisors. These methods are too complicated to describe in a short note, but I can give you an idea of how they work.

This nicely demonstrates the role of pseudoprime tests: If we can quickly tell that a number is *not* prime, we don’t need to bring out the big guns.

What follows is a brief version of the Fermat test, starting with its motivation:

If a number is primeand you take any number that is bigger than one but less than the prime, then it turns out that if you keep multiplying by that number, dividing by the prime and taking the remainder, if you do this one less times than the prime,the result is always 1. For example, 7 is a prime. Start with 3 and call that step 1. Multiply by 3 you get 9. Divide by 7 and take the remainder and you get 2. That's Step 2. Now multiply by 3 and you get 6. Divide by 7 and take the remainder and you still get 6. That's step 3. Continuing: step 4: 6 * 3 = 18; divide by 7, remainder is 4 step 5: 4 * 3 = 12; divide by 7, remainder is 5 step 6: 5 * 3 = 15; divide by 7, remainder is 1 So after 7 - 1 steps you get 1.

What we are doing is raising 3 to the \((p-1)\)st power, here the 6th, but keeping only remainders with respect to *p*..

We can write this more easily in terms of modular arithmetic, in which \(a\equiv b\text{ (mod }m\text{)}\) means that \((a-b)\) is a multiple of \(m\), so that the remainder when you divide it by \(m\) is zero. In particular, a number is congruent to (\(\equiv\)) its remainder. The work above becomes $$3^2=3^1\cdot3=3\cdot3=9\equiv2\text{ (mod 7)}\\3^3=3^2\cdot3\equiv2\cdot3=6\equiv6\text{ (mod 7)}\\3^4=3^3\cdot3\equiv6\cdot3=18\equiv4\text{ (mod 7)}\\3^5=3^4\cdot3\equiv4\cdot3=12\equiv5\text{ (mod 7)}\\3^6=3^5\cdot3\equiv5\cdot3=15\equiv1\text{ (mod 7)}$$ That is, $$3^6\equiv1\text{ (mod 7)}$$ This will be true for any prime \(p\) and any smaller number \(a\): $$a^{p-1}\equiv1\text{ (mod }m\text{)}$$ This is called Fermat’s Little Theorem.

Now look at it the other way around. Start with a number and suppose you don't know whether it's prime or not. Take a number between 1 and the number and go through the steps I've described. Suppose youdon't get a 1. Then you know the numberISN'T a prime.

For example, if we test \(p=10\) for primality, using \(a=3\) again, we get

$$3^2=3^1\cdot3=3\cdot3=9\equiv9\text{ (mod 10)}\\3^3=3^2\cdot3=9\cdot3=27\equiv7\text{ (mod 10)}\\3^4=3^3\cdot3\equiv7\cdot3=21\equiv1\text{ (mod 10)}\\3^5=3^4\cdot3\equiv1\cdot3=3\equiv3\text{ (mod 10)}\\3^6=3^5\cdot3\equiv3\cdot3=9\equiv9\text{ (mod 10)}\\3^7=3^6\cdot3\equiv9\cdot3=27\equiv7\text{ (mod 7)}\\3^8=3^7\cdot3\equiv7\cdot3=21\equiv1\text{ (mod 10)}\\3^9=3^8\cdot3\equiv1\cdot3=3\equiv3\text{ (mod 10)}$$ That is, $$3^9\equiv3\not\equiv1\text{ (mod 10)}$$ So 10 **can’t** be prime, because if it were, the result would have been 1. (Yes, we knew that already; this is *far* more useful for large numbers!)

Unfortunately, if you do end up with a 1, you can't say for sure that the numberisa prime. But there are fancier versions of this basic idea that will tell you a number isalmost certainly a primeif it passes the test. Also, in the version I've described you have to do an awful lot of multiplying and dividing to do the test. But it turns out you can do the test much faster than the way I've described.

We’ll see more tests next week. We’ll see how to speed things up right now.

Another 1998 question demonstrated the full Fermat test:

Prime Number Tests Is the number 55,409,243 prime? Also, how can you test to see if a number is prime or not?

Doctor Rob answered, starting again with the simplest such test:

No, 55409243 is not prime. You ask a very good question about testing for primality. There are quite a few ways to do that.They range from the very simple, yet time-consuming, to the very sophisticated and quite fast.The simplest way is to useTrial Division. Let N be the number in question to be tested.Divide by all prime numbers less than or equal to sqrt(N). If none go in evenly, then N is prime. In your case, you would divide by all the prime numbers less than 7443.73, of which there are more than 900.

I won’t carry out this test!

Here is a slightly more complicated way. 1) Pick any a with 1 < a < N-1. 2) Find thegreatest common divisord of a and N. If d > 1, thenN is composite, and d is a factor. If d = 1, then compute the remainder of a^(N-1) when divided by N. If this is not 1, thenN is composite. If this is 1,you can't tell if N is prime or not. Most composite numbers will be revealed to be composite by this method, however. This method is called theFermat Test.

Let’s apply that to our number, \(N=55,409,242\):

In your case, I picked a = 3, and found that a^(N-1) left a remainder of 4483955 when divided by N, so N cannot be prime. This computation involved26 squaringsof 8-digit numbers,15 multiplicationsby 3, and26 divisionsby N. This is slightly less work than900-odd divisionsof N by small primes.

You can’t just calculate \(3^{55,409,242}\) and then divide by 55,409,243; calculators can’t hold the numbers that would be involved. (This number would have something like 26 million decimal digits!) We don’t even want to do all 55,409,242 multiplications using remainders, as we did above. To speed the work, we square repeatedly to get large powers quickly, finding remainders at every step to keep the numbers small. There are several variations of this method; here is one version of the work, in which we repeatedly divide the exponent by 2 while squaring the base (modulo *N*), and multiply the current “result” by the power of the base if the exponent is odd. Each of the 26 rows after the first represents a squaring (and a division by the modulus), and each of the 15 results shown is a multiplication.

$$\begin{array}{rrr}\text{exponent}&\text{base}&\text{result}\\

55409242&3&1\\

27704621&9&9\\

13852310&81&\\

6926155&6561&59049\\

3463077&43046721&22214947\\

1731538&15197407&\\

865769&50930095&49381973\\

432884&21872735&\\

216442&327634&\\

108221&16334265&6737364\\

54110&19328578&\\

27055&43264463&22944554\\

13527&44210924&37489537\\

6763&38849675&51437798\\

3381&1515241&24542770\\

1690&17895133&\\

845&4492694&36364969\\

422&41974568&\\

211&36342724&50016120\\

105&26976110&21228392\\

52&33128489&\\

26&33942363&\\

13&9662916&48207464\\

6&1738737&\\

3&22647846&26937243\\

1&14529912&4483955\\

0&39781892&{\color{red}{4483955}}\end{array}$$

I used a spreadsheet to do this. Since the final result is not 1, this number can’t be a prime.

And it turns out (thank you, Wolfram Alpha) that \(6997\times7919=55,409,243\).

Next time, we’ll dig a little deeper into this test, and then look at some that are more advanced.

]]>

We’ll start with this question from 2008:

Checking if a Number from 1-100 is Prime What is an easy way to determine if a number is prime? Example:Write the number 100 as the sum of two prime numbers. For me it is difficult todetermine whether or not a number is prime. I can but it takes a while. I want to know a simpler way than trying to multiply a bunch of numbers together. Well some are obvious but if I'm going from 1-100 I need an easy way.

The problem itself requires trial and error: You have to look at a list of primes and try to find pairs that add to 100 (perhaps by subtracting each prime from 100 and seeing if the result is on the list). We gave such a list three weeks ago: $$2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97$$

When we try 97, we find that \(97+3=100\); similarly, \(89+11=100\), \(83+17=100\), \(71+29=100\), \(59+41=100\), \(53+47=100\). There is no shortcut for this.

But what if you don’t have such a list? That’s where Brooke wants help.

Doctor Rick answered:

Hi, Brooke. There isn't a really easy way, butyou can write your own list of prime numbers less than 100without much trouble (if you can't look up the list, as in our FAQ). I'll give you some pointers, because it will turn out to be useful every now and then to know the primes under 100.

What we’ll be doing here is not the most efficient way, but is intended to help Brooke gain an understanding of primes and divisibility tests, not only for making a list but also for checking if an individual number is a prime. (Next week, we’ll look at efficient ways to do the latter.)

Doctor Rick’s suggestion is to check each number individually, using the tests he’ll list; I’ll do it to all the numbers in parallel, to save writing, which will lead up to the fast method we’re heading toward.

We’ll start with all the numbers from 1 to 100:

If a number can't be divided by any prime number less than or equal to thesquare rootof the number, then it is prime. (If you don't know this, we can discuss it further!) This is a big help, because it means thatwe can find all the primes under 100 by checking for divisibility by the primes 2, 3, 5, and 7. The next prime, 11, is greater than the square root of 100 (namely, 10). This immediately rules outall numbers ending in an even digitexcept 2 (because they are divisible by 2), andall numbers ending in 0 or 5except 5 itself (because they are divisible by 5). All other primes less than 100 must end in 1, 3, 7, or 9.

We’ll see below (and also next week, a different way) why we can stop at the square root.

Here I’ve crossed out all the even numbers (red) and remaining multiples of 5 (green), and erased 1, which is neither prime nor composite:

These divisibility tests are particularly easy, because our base, 10, is a multiple of both. That also makes this easy to represent in a table with rows of 10!

A number isdivisible by 3if thesum of its digits is divisible by 3. That's easy to check for two-digit numbers. Among the numbers in the 50s, for example, this eliminates 51, 54, and 57. We already knew 54 was out, but now our list is down to 53 and 59. You should know your 7-times table and realize that neither of these numbers is on it, so they are both prime. If you've learned up through 7 times 12, then you don't need to actually do a division until you get past 84. That's not bad!

Here I’ve erased what I crossed out before, and crossed off all remaining multiples of 3 (red) and of 7 (green):

These tests are considerably harder than for 2 and 5; the method we’ll see next eliminates that difficulty.

Going through the numbers from 2 through 99 in order, I can construct the list of primes fairly quickly. You'll find that the more you do this, the more you'll start recognizing primes in this range. I mess up once in a while, such as thinking that 91 is prime--so I still have to check my list by doing the division by 7. Most of the work, though, as I said, is pretty quick.

Here is our final result:

This agrees with our list above.

Now let’s make the process more efficient, by avoiding the divisions (or divisibility tests) entirely.

Here’s a question from 2002 about a far more efficient method:

How does the Sieve of Eratosthenes Work? I'm in the 6th grade and right now we are working on the "sieve of Eratosthenes." I'm wonderingwhy and how it works. Thanks for all your help - you make math actually kinda fun! -S

A sieve, in real life, is a device with a screen, or many holes, that can let small particles pass through, while holding back large particles or clumps.

This metaphorical sieve is an idea attributed to the ancient Greek mathematician Eratosthenes. Here, the “large particles” it removes are the composite numbers, which are “clumps of primes”. Prime numbers are like grains of sand, or like atoms, from which molecules are made.

Doctor Ian answered, demonstrating with a small example:

Hi S, We start out with some set of numbers. Normally, that's 1 to 100, but I don't want to write all those, so I'm going to go from 1 to 30. The idea stays the same, though. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 We start by getting rid of 1, becausethe definition of 'prime' excludes 1: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 The smallest prime is 2. But anything that is _divisible_ by 2 can't be prime, right? So we cankeep 2, and cross out all its multiples: 2 3 5 7 9 11 13 15 17 19 21 23 25 27 29 As you can see, that wipes out half the numbers we started with!

Although in typing he chose to *erase* the multiples, the work is easier if you circle the prime and *cross off* its multiples as he said, leaving them in place:

In this case, we just **cross off every second number** – no multiplication or division is needed. The same will be true for larger primes as we proceed.

The next prime is 3. We're going to keep that, and again, we'llwipe out the multiples of 3- since if something is divisible by 3, it can't be prime: 2 3 5 7 11 13 17 19 23 25 29

Here we cross off **every third number** (half of which have already been crossed off, because they are even); I crossed in a different direction this time just to make them stand out – you don’t have to distinguish this when you do it:

Again, I just had to “count by threes”, and never had to multiply or divide.

Now, what about 4? When we eliminated multiples of 2, we also eliminated multiples of 4, 6, 8, and every other even number! This is how the sieve works so quickly: every time you eliminate the multiples of a prime number, you never have to check those multiples.

As we proceed, all the multiples of any composite number will already have been crossed off when we come to it, so we just skip it. We only check divisibility by primes, which we discover as we go.

So we can justskip to the next prime number, which is 5. Removing the multiples of 5 leaves us with 2 3 5 7 11 13 17 19 23 29 And at this point, we'd need numbers over 30 in the sieve to see any effects, since everything we have left is prime.

The only new number we cross off is 25:

There are no multiples of 7 remaining (we’ll see why below), so we can stop.

But do you see the main idea? It's sort of like a game that you can play with an audience full of people. Ask everyone to stand up. Thentell everyone with an 'a' in his or her last name to sit down. Then tell everyone with an 'e' in a last name to sit down. (Note that someone named 'Apple' would already be sitting.) Then do the same for 'i', 'o', and 'u'.Who will be left standing?Only people with no vowels in their names! That is, people with names like Ng, or Kyzyl, or Flynn, or Zbrtzk. If we order the vowelsfrom most frequent to least frequent(eaoiu), then each vowel will eliminate fewer people - partly because it's used less often, and partly because many people have more than one vowel in their names (in much the same way that 6 gets eliminated as a multiple of 2, so it isn't around to be eliminated as a multiple of 3). Does this make sense?

In our sieve, we started with the most frequent multiples, and each subsequent prime has fewer.

Now let’s look at that square root idea that was mentioned before.Â Here’s a question from 2012:

The Sieve, and Ceiling, of Eratosthenes I want to teach my kids about prime numbers with the Eratosthenes Sieve, but I have noticed thatsome websitessay to use the factors, 2, 3, 5, and 7, whileotherssay to use all those numbers AND the number 11. Why is that so? and won't it make a difference to the answer?

I answered:

Hi, Lin. Can you give me an example of such a site? How they word it will make a difference. How far you go down the list of primes depends on how big a sieve you are making. Most likelythose that used 11 were finding primes past 100; or else, possibly, they wereusing 11 to help students discover the point I'm about to make, the upshot of which is that, if you are finding primes through 100, you DON'T need to go as far as 11. That's a good thing to experience.

I have more than once encouraged a student to try something I knew would not work, so they could discover for themselves (and hopefully remember) *why* it wasn’t necessary.

I chose to use an intermediate-sized example:

Let's do a smaller sieve, up to 50, and see how far we have to go. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 We first mark 2 as a prime and strike out all its multiples: ( 2) 3 / 5 / 7 / 9 // 11 // 13 // 15 // 17 // 19 // 21 // 23 // 25 // 27 // 29 // 31 // 33 // 35 // 37 // 39 // 41 // 43 // 45 // 47 // 49 //

Here, rather than erasing numbers, I showed only the crossings, in order to keep the places, which help in finding multiples by counting.

Now, thefirst remaining number, 3, has been shown to be a prime, because it is not a multiple of any prime before it. So we repeat the process with 3, striking out 9, 15, 21, 27, 33, 39, and 45: ( 2)( 3) / 5 / 7 / / // 11 // 13 // // // 17 // 19 // // // 23 // 25 // // // 29 // 31 // // // 35 // 37 // // // 41 // 43 // // // 47 // 49 // Now we see that5 is the next prime, so we strike out all its multiples that remain -- namely, 25 and 35: ( 2)( 3) / ( 5) / 7 / / // 11 // 13 // // // 17 // 19 // // // 23 // // // // // 29 // 31 // // // // // 37 // // // 41 // 43 // // // 47 // 49 // Nowthe next prime is 7. But when we go to strike out its multiples, we find that there is only one -- namely, 49: ( 2)( 3) / ( 5) / ( 7) / / // 11 // 13 // // // 17 // 19 // // // 23 // // // // // 29 // 31 // // // // // 37 // // // 41 // 43 // // // 47 // // //

Here is the key:

We COULD now try the next prime, 11; butwe'd have nothing to do!Why is this? Well, did you notice that in each step,the first number we struck outwas the SQUARE of the prime we were working with? 2^2 = 4 3^2 = 9 5^2 = 25 7^2 = 49 There's a good reason for that: any multiple of, say, 7, less than 7*7 has already been struck out because the other factor is smaller than 7! So when we come to 11,the first number we'd strike out would be 121, and that's not in our table of the first 50. (It isn't even in the table for primes through 100.)

This gives us our first shortcut: Don’t **start** counting multiples at the prime itself; start at its **square**.

It also tells us when we can stop:

Therefore, we already know that nothing more will be stricken (ever!), so we canmark all the remaining numbers as prime: ( 2)( 3) / ( 5) / ( 7) / / // (11) // (13) // // // (17) // (19) // // // (23) // // // // // (29) // (31) // // // // // (37) // // // (41) // (43) // // // (47) // // // The lesson here is that the first number you DON'T have to use isthe first prime the square of which is GREATER than your maximum number, or that squares beyond the largest number in the sieve. To put that the other way around, you only have to use primes that areLESS than the SQUARE ROOT of the maximum.

You don’t need to have calculated the square root ahead of time; in doing the sieve, you will be squaring each prime to find the first multiple, and **when the square is past the end**, you **stop**. That’s our second shortcut.

So one way to present the sieve of Eratosthenes up to 100 is to just tell your kids that they can stop after 7 -- but then they may not know why, and the process may seem arbitrary.For the sake of insight, deliberately include 11before exploring why you don't need to use it. Now, suppose you were makinga sieve for numbers through 1000. What is the last prime you would have to use? It won't be either 7 or 11.

The square root of 1000 is about 31.6; so you’ll stop before you reach 32. That last prime will be 31, which we’ve seen above; but we don’t need to know that before we start!

Here’s a summary of the method, at its most efficient:

- Write out all the numbers from 1 through N. Drop 1, which is neither prime nor composite.
- Circle the first remaining number on the list, which initially is 2. That’s a
**prime**(call it*p*). - Square the prime
*p*, and cross it off. If this is past the end of your list, stop; all the remaining numbers are**prime**. - Starting there, cross off every multiple of
*p*, by repeatedly adding*p*. These are**composite**. - Return to step 2 and repeat.

So let’s close with that sieve for 1000. Each time I mark a prime (with a new background color), I’ll cross out its remaining multiples using that color:

Everything not crossed off is a prime.

Once I had marked 31 as prime, since its square is 961, only that one multiple had to be crossed out (992 being already eliminated), and all remaining unmarked numbers are prime. (All this was done by conditional formatting in a spreadsheet – I didn’t really do all that work by hand!)

It is entirely accidental (honest!) that this post, for Christmas, is about Making a List, and will be followed by Checking Them (twice). Santa Claus is coming to town!

]]>

We’ll start with this question from 1999:

Why Aren't There Negative Prime Numbers? Can negative numbers be prime numbers? In my math book it says that a prime number is awhole number greater than 1that has only two factors, 1 and itself. So why can't, for example, (-5) be prime? Its factors would be -5 and 1. I don't get it. Is it because 5 and (-1) are also factors of (-5)? I say no because (-1) and (-5) would then be factors of 5, and 5 wouldn't be prime. I don't understand and neither does my teacher. We tried to figure it out, and then she told me to ask you.

Edgar’s definition clearly doesn’t allow negative primes – not only because it specifically says so, but also because, for example, \(-5\) would actually have **four** factors (\(-5,-1,1,5\)), and so would \(5\). (I think Edgar may be confusing the idea of individual factors with factor *pairs*.)

Later we’ll consider *extending* the definition to include negatives; but for now, we have to take the definition as given.

Doctor Ian answered:

Hi Edgar, This is an excellent question, but in order to understand the answer, you have to get a feel forwhat mathematics is about. It's not about cranking numbers through equations and getting answers, and it's not about balancing your checkbook or figuring out how long it will take Bill and Janet to mow the lawn if they work together, and it's not about building bridges or telephones or sending spaceships to other planets. Those are all _uses_ of math, butmathematics itself is about searching for patterns. The most interesting patterns are the ones that hold for the largest classes of numbers. So something that is true for all numbers is more interesting than something that is true for just integers, or just prime numbers, or just numbers smaller than 10, or just the number 17. (Note that 'patterns' are sometimes called 'theorems,' and sometimes called 'properties'. For example, the prime number theorem, which says that any composite number can be broken into a product of primes, is one kind of pattern. The commutative property of addition, which says that you can add numbers in any order, is another kind of pattern.)

So the important thing about primes, even before their usefulness, is the universality of facts about them. If a change in definition would result in major exceptions, it would be problematic.

Before anyone figured out the need for negative numbers, mathematicians had already discovered lots of patterns involving prime numbers. So when negative numbers came along, making some of them prime would have caused a lot of patterns (patterns that looked like "For any prime number, blah blah blah") to stop being true. That would have been annoying without serving any real purpose, and sothe definition of primes was adjusted to exclude negative numbers. This, by the way, is why zero and one aren't prime numbers either, although you can make some good arguments for why they should be. If they were considered prime, then a lot of patterns that now look like "For any prime number, blah blah blah" would have to be changed to "For any prime number except one or zero, blah blah blah." That makes the patterns uglier, and harder to remember. ("Oh, wait - does this pattern for prime numbers also apply to zero?")

What patterns would negative primes break? Certainly one would be the Fundamental Theorem of Arithmetic, which says that any number can be written uniquely as a product of primes. This would not be true if \(2, 3, -2, -3\) were all primes, because \(6=2\times3=-2\times-3\), for example. So we’d at least have to *change how we state* the patterns when all integers are in view.

A question from Tom in 2000 led to a different possibility:

Is -1 Prime? My class discussed prime numbers. The class noted that-1 has exactly two factors(namely 1 and -1) and asked why it wasn't listed as a prime number. I reiterated the definition, but they weren't satisfied. Do you have any further information on this topic?

This takes the question one step further than Edgar’s: If we just drop the restriction to positive numbers, the definition would allow \(-1\) to be prime (but not 1 or other negative numbers).

I answered first, referring back to that last answer, and adding:

I assume that your definition of prime includes the word "positive," as in our FAQ. If the students are askingwhy the definition doesn't allow for negative primes, then this and other answers we have given should help.

So, there are really two issues: **What** their definition says, and **why** the definition **should** include that restriction. (Our FAQ says essentially what the first answer two weeks ago said.)

Tom replied:

Thanks for writing back, Dr. Peterson. After writing you, students found the FAQ you enclosed and were appeased. The book we are using, Glencoe, defines a prime number as "Anumberthat has exactly two factors, 1 and the number itself." I showed them a couple of other definitions that include natural numbers, counting numbers, or positive integers. They now want to write to the company and suggest a correction. One of the authors teaches in nearby Unionville-Chaddsford, so we may make this a letter-writing lesson too. Thanks for your help.

So their definition was defective, omitting the restriction to natural numbers (or perhaps taking “number” to mean that).

But then Doctor Floor had something to add:

Dear Tom, I read the discussion you had with Dr. Peterson. Indeed it is true thatin the usual definition of a prime, the prime is supposed to be a positive integer, or natural number. However,there are people, and not the least, who do consider -1 to be a prime. Professor John Conway of Princeton is one of them. Although I don't suppose it is desirable to have this in high school textbooks, I would like to point you to a newsgroup discussion thread about this subject: -1 as a Prime (geometry-research, Math Forum) http://mathforum.org/kb/message.jspa?messageID=1093170 A lot of this thread is useless, but the first (and later) messages by John Conway do explain why he considers -1 a prime, and why this is useful in his opinion. I hope you appreciate this addition.

We’ve heard from Professor Conway last week, and also here. The discussion, no longer accessible at the old address, appears to be now found here; it is in response to a criticism of Conway’s explanation in his book The Sensual (quadratic) Form, where he says in the preface,

(Don’t ask me why someone would call infinity a prime within this specialized field.)

His first actual use of this convention is on page 95:

(Take a moment to ponder how different this is from the standard usage.)

Here is what he says in the discussion, responding to a complaint about the first quote:

> he gives a list of four example statements that he claims are stated most concisely if -1 is considered to be a prime. his first example is “

every nonzero rational number is uniquely a product of powers of prime numbers p“; apparently he’s too stupid to realize that -6 is both 2*3*(-1) and Â 2*3*(-1)*(-1)*(-1).I worded that statement more carefully than you’ve read it.

There is indeed a unique way that -6 is a

product of powers of distinct primes– namely those powers are -1, 2, and 3. There are only two powers of -1, namely 1 and -1.…

[L]et me say that I’m very puzzled indeed as to why my calling -1 a prime so enrages you. I did so for a very real reason, not just for fun. Namely, the theory of quadratic forms largely consists of statements – let me call the typical one “Statement(p)” – that are usually only asserted for the positive primes p = 2,3,5,… . Now in my experience, in almost every case when Statement(p) is true for all positive primes, it’s automatically

both meaningful and true for p = -1 too, and moreover, that additional assertion is just as useful.Of course, it’s also the case that -1 does behave differently to the positive primes, but the way this happens is usually that MORE is true when p = -1, not LESS. If LESS were true, then it would indeed be silly to count -1 as a prime, but since it’s almost always MORE, it’s silly not to.

Let me discuss the simplest such statements in this light.

First, the form of the statement of unique factorization that I prefer is:

The multiplicative group of the non-zero rationals is the direct product of the cyclic subgroups generated by “my” primes, namely -1,2,3,5,… .

The additional thing that’s true here is that the subgroup generated by -1 has order 2.

Of course you can still state this with “your” primes, but then have to say “generated by -1 and the primes”, which makes it just a little bit longer.

…

My point is that this a priori silly idea is actually so sensible a posteriori that

inside quadratic form theoryit’s well worth while changing the accepted convention. But of course you don’t have to – by all means use the longer statements if you prefer them.

This illustrates the fact that we can modify a definition when it makes things easier in a particular field. Definitions are tools of mathematicians, not their masters; and Conway was known as a particularly creative mathematician. He is not proposing that this redefinition be used everywhere.

A 1997 question from “Muskrat” broadens the context even further:

Prime or Composite? Wouldn'tevery numberbe composite? The reason I think this is because the definition of PRIME is that itonly has 2 factors...itself and 1... but what about thedecimals? Those are numbers, aren't they? I think the definition of factor or prime and composite needs to be defined better, don't you? Because doesn'tevery numberhave another number that can go into it? I have another question: in one of your answers you said 0 was a number, but I don't think it is. Isn't zero considered something else? And about factors: every number has a factor, sozero isn't a number. I rest my case.... even 1! see...there is... .5! or .25!

Yes, *his* definition has to be improved; it is missing some things.

Doctor Rob answered, first clarifying the terms used:

The definitions of prime and composite numbers are fine the way they are.Probably you haven't seen them written out with precision and in detail.I will make an attempt to clarify this for you below. First of all, we shall speak only of theNatural Numbers, that is, the counting numbers. They are all integers, or whole numbers, and they are all positive. They begin 1, 2, 3, 4, ... . Adivisorof a natural number N is a natural number D such that N = D*Q for some unique othernatural numberQ. A prime number in this set is a number with exactly two divisors. Since the number itself and 1 are always divisors, in order to have just two divisors, the number must be bigger than 1, and it must not have any divisors other than 1 and itself.

This is one missing detail in Muskrat’s understanding: 1 does *not* have 0.5 as a factor (divisor), because divisors must be integers.

The natural number 1 is very special. It is called aunit, and it is the only natural number that has a natural number reciprocal, that is, a natural number I such that 1*I = 1. Acompositenumber is a natural number which is neither aprimenumber nor aunit.

So the natural numbers split into these three sets: units, primes, and composite numbers.

The big deal about prime numbers is theFundamental Theorem of Arithmetic. It says thatevery natural number can be written uniquely as a product of powers of prime numbers. This is a very important fact, as you might be able to tell by its name! That disposes of most of your objections above.1 is not a primebecause it has only one divisor, itself.Zero, negatives, and decimal fractionsare neither prime nor composite because they are not natural numbers. They belong to a larger set, either the Integers, the Rational Numbers, or the Real Numbers.

This covers everything we discussed in the last two weeks.

Now, we can move beyond that:

The next question iswhether we can extendthe notion of a prime number to one of these larger sets. In the case of theIntegers, this works pretty well, but we have to be careful! Now there aretwo units, 1 and -1. To every prime number P in the natural numbers there correspond two integers that are "prime" in the integers: P and -P. These now have exactlyFOUR integer divisors: 1, -1, P, and -Pdivide each of the numbers P and -P, and no other integers do. Notice, however, that there are only two of these divisors that are natural numbers. Likewise to every composite number C in the natural numbers there correspond two integers that are composite in the integers: C and -C.

So if we choose to work with integers, we have to **change the definitions**, so that a prime has exactly **four divisors**, rather than two (and a unit has exactly **two**). This way, we **can** talk about negative prime numbers – because we are now living fully in the world of integers, not just using old definitions in a new context.

Now we have to worry aboutzero. Zero is a special case, because it hasinfinitely many divisors, since every integer except zero divides it. Zero is relegated to a new class, neither unit, nor prime, nor composite. The class is called thezero-divisors. Zero is the only zero-divisor in the integers. What happens to theFundamental Theorem of Arithmeticin this setting? Now it says thatevery non-zero integercan be written uniquely as aunit times a product of powers of prime natural numbers(or positive prime numbers).

So we’ve also changed the theorem to apply in this bigger world. (We could instead restate this using both positive and negative primes.)

When we try to extend to theRational Numbers, we are in big trouble: every non-zero rational number is a unit! The same happens in the real numbers. There are no "prime" numbers and no "composite" numbers in those sets, just units and zero-divisors (zero is the only one).

But did you notice that Conway mentioned rational numbers in his version of the FTA? There may be a way to do this, after all. But it, too, will require changes.

I’ll close with this 2003 question:

Can A Negative Integer Be Factored Into Primes? Can the number -103,845 have the prime factors of 3, 5, 7, 23, and 43? We find this confusing because we have been told a positive number can have prime factors but a negative number can't.

If there are no negative *primes*, how can you *factor* a negative number as a product of primes? This is another context issue.

Doctor Tom answered, emphasizing the concept of **unit**:

Hi Louisa, It just depends onwhat you consider to be a prime. It turns out that there is a large collection of mathematical structures that can support something like a prime factorization, and the set of integers is just one example. These are usually called "Euclidean domains" in the area of abstract algebra. What's usually done to avoid confusion is to identify theunitsof the system. Units are factors of 1. For the integers, the units include 1 and -1. Prime numbers in these systems are said to beequivalentif you can obtain one from another by multiplying by a unit, so with that understanding, the primes of the integers are 2 and -2, 3 and -3, 5 and -5, and so on. Factorization is then not unique, but ISunique up to a multiplication by units.

That is, in calling the factorization unique, we ignore any 1’s or -1’s that might be inserted.

If you just consider thepositive integers, the only unit is 1, so the prime factorization is totally unique. If you include thenegative integers, then you've got uniqueness only up to units. Often people only consider the positives to avoid this confusion.

As we’ve said, the idea of primes originated in a world that didn’t know about negative numbers, so there was no issue. If we choose to expand our world to the integers, we just have to make this little addition.

But we can expand still further, as we also touched on last week:

Just for fun, here'sanother Euclidean domainyou might like to explore. Let i be the (imaginary) square root of -1. The numbers in the system are the so-called "Gaussian integers"--numbers having the forma + bi, where a and b are integers. There is still prime factorization in the Gaussian integers, and interestingly some of the numbers that were prime in the normal integers are no longer so in the Gaussian integers. For example, the number 2, which is written as 2 + 0i, can be factored into (1 + i)(1 - i). Both 1 + i and 1 - i are primes in the Gaussian integers. To see why the idea of units is important, look at the Gaussian integers. In that system, there are four units: 1, -1, i and -i.

This is left for the reader to explore!

Louisa wrote back:

Dear Dr. Tom, Crystal, Darlene, and I would like to thank you for not only answering our question about factoring a negative number but also for returning it so quickly. We had a parent send us a Dr. Math response onnegative numbers not being factors of positive numbers. He felt this meant our bonus question asking for the prime factorization of -103,845 meant it could not be factored. We felt our problem was different than what he was answering. That is when we turned to you. We had no idea your response would be so quick and helpful. Thank you. Louisa

The answer they read may have been Are Negatives Factors of Other Numbers?, from a few months earlier, which was about a somewhat different issue; the answer there was that the meaning of “factor” depends on context, and that for a certain question on a standardized exam, negative factors would probably not be in view.

We see now that the answer to the problem is \(-103,845=-1\times3\times5\times7\times23\times43\), where \(-1\) is not a prime, but a unit.

]]>

First, here is a question from 1995:

Why is 1 Not Considered Prime? Just recently a grade six student asked me "Why is 1 not considered prime?" I tried to answer but could not, since I do not understand this either. I thought the explanation might lie in the fact that "we" don't use the true definition or we are interpreting it wrong. A prime is normally described asa number that can be expressed by only one and itself. We exclude all non-natural numbers from the set that we will be working on and then everything is fine except for when we work with 1. 1 = 1 x 1. That is,one equals 1 times itselfand there is no other combination. Now to the grade six student in Faro Yukon, I said there may be a small print clause in the contract with the math gods that says you can only write it once, since 1 also equals 1x1x1x1x... This would not work for other primes such as two: 2 does not equal 1x2x2x2x... Likewise, 3 does not equal 1x3x3x3x... Patterns are very important to mathematics, I further explained, andthis is a pattern I see being broken. I showed this in a slightly different way to the grade sixer but in essence the same. My question to you, Dr. Math, iswhat is the small print in the contract with the Math godsand how do we explain it to the grade six kids who are supposed to know it?

At one level, we could just say that his copy of the “contract” is missing a word or two. As we saw last time, our definition is “a positive number that has **exactly two factors**, 1 and itself”. That excludes 1.

But we can go much deeper: **Why** should the definition be written to exclude 1? Why not omit those extra words?

Doctor Ken answered:

Hello there! Yes, you're definitely on the right track. In fact, it's precisely because of "patterns that mathematicians don't like to break" that 1 is not defined as a prime. Perhaps you have seen the theorem (even if you haven't, I'm sure you know it intuitively) that any positive integer has aunique factorization into primes. For instance, 4896 = 2^5 * 3^2 * 17, and this is the only possible way to factor 4896. But what if we allow 1 in our list of prime factors? Well, then we'd also get 1 * 2^5 * 3^2 * 17, and 1^75 * 2^5 * 3^2 * 17, and so on. So really,the flavor of the theorem is true only if you don't allow 1 in there.

Incidentally, the full wording of this Fundamental Theorem of Arithmetic is “every integer *greater than 1* can be represented uniquely as a product of prime numbers, *up to the order of the factors*“, because rearrangement is allowed, but not changing exponents.

So why didn't we just say something like "a prime factorization is a factorization in which there areno factors of 1" or something? Well, it turns out that if you look at some more number theory and you accept 1 as a prime number, you'd have all kinds of theorems that say things like "This is truefor all prime numbers except 1" and stuff like that. So rather than always having to exclude 1 every time we use prime numbers, we just say that 1 isn't prime, end of story.

Definitions are what they are in order to be useful; they are crafted to make what we usually want to say as easy as possible. Since 1 would get in the way so often, we exclude it.

Incidentally, if you want to call 1 something, here's what it is:it's called a "unit"in the integers (as is -1). What that means is that if we completely restrict ourselves to the integers, we use the word "unit" for thenumbers that have reciprocals(numbers that you can multiply by to get 1). For instance, 2 isn't a unit, because you can't multiply it by anything else (remember, 1/2 isn't in our universe right now) and get 1. This is how we think about things in Abstract Algebra, something sixth graders won't need to worry about for a long time, but I thought I'd mention it.

In 2002, an anonymous reader asked for clarification on one phrase:

Reading the explanation of why 1 isn't prime, I came across the sentence "Remember,1/2 is not in our universe right now." What does this mean?

I explained:

This reflects the condition previously given, "if we completely restrict ourselves to the integers...". That means that we are only considering the integers, and not thinking about any other kind of number;the set of objects under consideration is called the "universe."Any object not in that universe does not exist, as far as the problem at hand is concerned. In this case, since the reciprocal of 2 is 1/2, but 1/2 is not an integer, we say that 2 _does not have_ a reciprocal, and thus is not a "unit."

But as the next question, from 2004, reveals, not everyone has always agreed with that definition:

Was 1 Ever Considered to Be a Prime Number? I learned that a prime number was onedivisible by only itself and 1, but my 4th grader says that per her book a prime requires2 different factors. I note your Greek reference for 1 not being prime, which would indicate that I'm wrong and there was no change in definition. However, Ray's New Higher Arithmetic (1880) states, "A prime number is one that can beexactly divided by no other whole number but itself and 1, as 1,2, 3, 5, 7, 11, etc." Can you tell me when this change happened and why?

The “Greek reference”Â may refer to our FAQ, which refers to the Sieve of Eratosthenes (to be discussed later), which *in our version* starts by crossing out 1 as not being prime. (If it were called prime, then we would circle it and then cross out all its multiples – that is, every other natural number, so that *only* 1 would be prime!) That may not, however, be exactly how Eratosthenes saw it. In those times, 1 wasn’t even considered a number! Euclid, for example, calls 1 not a number at all, but a “unit” (not in the sense we’ve used here). So of course 1 was not a prime.

But what about this 1880 book? On page 59, it says,

Doctor Rob answered, giving much the same argument as we used before:

Thanks for writing to Ask Dr. Math, Jim! I believe the 1880 book you cited is wrong--1 has never been and will never be considered a prime. If you treated 1 as a prime, then the Fundamental Theorem of Arithmetic, which describes unique factorization of numbers into products of primes, would be false, or would have to be restated in terms of "primes different from 1." The same is true of many other theorems of number theory and commutative algebra. Rather than use this phrase,it makes more sense to define primes so as not to include 1. Also, the multiplicative inverse of 1 (reciprocal of 1) exists in the positive integers, which is true of no other positive integer. We call such numbers "units," and this property makes them different from non-units.

A couple days later, I added a different perspective:

Hi, Jim. I'm going to disagree slightly with what Dr. Rob told you: although the definition of primenever SHOULD have included 1, and DIDN'T in the late 20th century, this fact was not always recognized in the relatively distant past. This is discussed here:

http://mathworld.wolfram.com/PrimeNumber.html The number 1 is a special case which is considered neither prime nor composite (Wells 1986, p. 31). Althoughthe number 1 used to be considered a prime(Goldbach 1742; Lehmer 1909; Lehmer 1914; Hardy and Wright 1979, p. 11; Gardner 1984, pp. 86-87; Sloane and Plouffe 1995, p. 33; Hardy 1999, p. 46), it requires special treatment in so many definitions and applications involving primes greater than or equal to 2 thatit is usually placed into a class of its own. A good reason not to call 1 a prime number is that if 1 were prime, then the statement of the fundamental theorem of arithmetic would have to be modified since "in exactly one way" would be false because any n = n*1. In other words,unique factorization into a product of primes would failif the primes included 1. A slightly less illuminating but mathematically correct reason is noted by Tietze (1965, p. 2), who states "Why is the number 1 made an exception? This is a problem that schoolboys often argue about, butsince it is a question of definition, it is not arguable."

I'm assuming that the references from 1979 on, at least, say that primes wereformerlydefined to include 1, rather than using that definition themselves. Texts, also, may not always be careful about definitions; your "divisible by only itself and 1" may well beintended to imply that "itself and 1" are not the same number, or the question of whether 1 is a primemay not have been considered.

So the definition was refined when its unpleasant implications were fully realized.

Here is another discussion of this question that I found: http://mathforum.org/kb/message.jspa?messageID=1379707 Read especially John Conway's contributions, which point out that mathematicians recognized the need to clarify the definition when certain aspects ofabstract algebradeveloped in the 1900's, which gave them a new perspective on the question; but thatschool texts, as usual, were slow to adopt the corrected definition:

In the late 1800’s and early 1900’s, mathematics was being clarified in many ways, and this greater care with definitions was part of that development.

What follows is what Conway said; the address above no longer works, so I’m glad I quoted it:

The change gradually took place over this century[the 1900's], because it simplifies the statements of almost all theorems. If you count 1 as a prime, for example, numbers don't have unique factorizations into primes, because for example 6 = 1 times 2 times 3 as well as 2 times 3. It's a bit of a nuisance that Lehmer's1914"List of all prime numbers below 10 million"counts 1 as a prime. I think the development of number theory for other rings played a big part, because there one finds other "units" besides 1 (for instance +-1 and +-i in the Gaussian integers), and these units clearly behave in many ways that make them different from the primes. Other examples of the kind of thing that goes wrong if you count 1 as a prime are arithmetical theorems like "If p,q,r,... are distinct primes, then the number of divisors of p^a.q^b.r^c.... is (a + 1)(b + 1)(c + 1)... ."

Gaussian integers will be mentioned again, as will units.

Mathematicians this century [the 1900's] are generally much more careful about exceptional behavior of numbers like 0 and 1 than were their predecessors: we nowadays take care toadjust our statements so that our theorems are actually true. It's easy to find lots of statements in 19th century books that are actually false with the definitions their authors used - one might well find the above one, for instance, in a work whose definitions allowed 1 to be a prime. Nowadays, we no longer regard that as satisfactory. The changeover has been very gradual, and I'll bet there are publications from the last few years in which 1 is still counted as a prime--in other words, it's not yet complete.In the 1950s and 1960s, books that chose the new definition would always be careful to point out that they were doing so, and that most authors included 1 with the primes. The real thing that gets such a change accepted is when it gets into high-school textbooks. I think that perhapswe must thank "the new math" movement, which for all its faults did get some of the terminology and conventions into the high schools that had hitherto only been used in the Universities.School textbooks don't like to muddy the waters by explaining such things as variations in usage, so would tend to give just one definition.My guess is that you'll find that schoolbooks of the 1950s defined primes so as to include 1, while those of the 1970s explicitly excluded 1.

I added:

It sounds like your textbooks, and mine, might have used the old definition!

Are 0 and 1 prime, composite, … or something else? We’ve seen part of the answer in references to “units”. But there’s a little more to say.

Here is a 1997 question:

1 and 0: Prime or Composite? Is the numberonea prime or a composite number? Why? (Please put your answer in a form that a sixth grader can understand.) What is the numberzero? Prime or composite? Why?

Doctor Rob answered, necessarily expanding the question from “which is it?” to “what (else) is it?”:

Oneis neither a prime nor a composite number. A prime number is one with exactly two positive divisors, itself and one. One hasonly one positive divisor. It cannot be written as a product of two factors,neither of which is itself, so one is also not composite. It falls in a class of numbers calledunits. These are thenumbers whose reciprocals are also whole numbers.

Note his slightly different definition of composite numbers, which I like:

- A
**prime**is a number you can get by multiplying two numbers (not necessarily distinct) other than itself. That*isn’t*true of 1. - And a
**unit**is a number that you can multiply by some number (possibly itself) to get 1. That*is*true of 1 (and no other natural number).

Zerois not a prime or a composite number either. Zero has aninfinite number of divisors(any nonzero whole number divides zero). It cannot be written as a product of two factors, neither of which is itself, so zero is also not composite. It falls in a class of numbers calledzero-divisors. These are numbers such that, when multiplied by some nonzero number, the product is zero.

- A
**zero-divisor**is a number that you can multiply by some number other than zero to get 0. That is true of 0 (and no other integer).

At this level, the ideas of **units** and **zero-divisors** seem silly because there is **only one of each** (among natural numbers). We’ll get to that in a moment!

He gives the same reason we’ve seen before:

The most important fact of multiplication of integers is called theFundamental Theorem of Arithmetic. It says that every whole number greater than one can be written *uniquely* (except for their order) as the product of prime numbers. This is so important thatwe tailor our idea of what a prime number is to make it true. If 1 were a prime number, this would be false, since, for example, 7 = 1*7 = 1*1*7 = 1*1*1*7 = ..., and the uniqueness would fail.

We’ll close with this 2013 question, which starts with a different issue before moving to primes:

Zero and One, Each Unique in Its Own Special Way Since zero isn't apositive numberand it's also not anegative number, what is it? Does it have a special name?

I answered:

Hi, Gabby. Yes, its special name is "zero"!There is no need to come up with a separate name for a category that consists of only one number.So we say that every number is either positive, negative, orzero.

This led to another question:

Hello. We are Gabby's classmates.If there is only one unit (1), why is there a name for that?Rachel and Sophie

Where had they seen the term unit? What does it mean to them?

I replied, unsure of the level of their knowledge:

Hi, Rachel and Sophie. What is your understanding of the meaning of the word "unit"? One meaning is just asynonym for "one"(a single thing), and not a category containing the number one. This usage is particularly relevant in connection withfractions, where the unit tells you what the fraction is a fraction OF.

For examples, see Fractions: What Are They, and Why?.

Another meaning you might have in mind is sometimes used in connection with 1 in contrast to prime numbers and composite numbers; but the actual meaning is rather technical -- andit is used because 1 is NOT the only number of that type. For an explanation of that usage, see Why is 1 Not Considered Prime? http://mathforum.org/library/drmath/view/57058.html Prime or Composite? http://mathforum.org/library/drmath/view/57115.html What Kind of Number is One? http://mathforum.org/library/drmath/view/56062.html

Here I referred to the first answer in this post, and one we’ll see next week, and another I’ve omitted. I think their teacher had told them about one of these pages.

These tell you that the word "unit" is used for a number that has areciprocalwithin a given set. When you restrict yourself to thenatural numbers(as we usually do in talking about prime and composite numbers),1 is the only unit. Extending our attention to theintegers,-1 is also a unit. If we extend further to theGaussian integers(which you may never even learn about), there arefour units: 1, -1, i, and -i! We wouldn't use the word "unit" as a category if 1 were the only number EVER in the category; but these extended contexts give areason to define a categorythat is relevant to primes and contains 1, even though 1 is the only unit IN THE NATURAL NUMBERS.

This is similar to the fact that we probably wouldn’t have words like “commutative” if we hadn’t started studying other kinds of “numbers” and their operations.

One of these pages also describes that in extended contexts, 0 is part of a special category, called "zero-divisors." Again, amongintegersthere is only one of these, namely zero, and it would be silly to use the category "zero-divisors" when all we gain is a longer name. More important, this category, while somewhat relevant to prime numbers, is not relevant to Gabby's original question about positive and negative, so it wouldn't have been an appropriate answer to your original question. (If you're wondering what numbers other than 0 can be zero-divisors, the best example is inmodular arithmetic, which you may have seen in the form of "clock arithmetic.")

As an example, if instead of a number line you count around a clock, then \(3\times4=12\) will take you to the same place as 0; so 3 and 4 become zero-divisors.

This may be far more than you want to know -- and may not have anything to do with the use of "unit" you asked about -- but maybe it starts to crack open the door to let you seehow big math is!

Most students never get to see that math deals with “numbers” far beyond the natural or real numbers.

Then their teacher (whose email was being used) commented:

Hello, I am the teacher of the 5th graders (Gabby, Rachel and Sophie) who emailed you about zero's special name and units. They were so very excited to receive your reply. I appreciated all the information you gave and, even more so, the way that you wrote to them as though they areintelligent people capable of thinking deeply about math. They are, and your response reinforced that to them. I am very grateful. Christina Hull

I responded,

Hi, Christina. Thanks for letting me know. That's exactly what I try to do. I like "talking up to" kids, rather than talking down to them. But also, the question (especially the second one) fascinated me, and led me to put together ideas I hadn't combined before, so it was just fun to write them up.

Christina concluded:

Yes, their question and your answers led me to think about ideas I hadn't thought about in that way before, as well. And, in case you were wondering, they came up with the question while thinking about 1 fitting into a category other than prime numbers or composite numbers. Thanks again. Christina

That’s what makes it fun to be a Math Doctor!

]]>

We’ll start with an anonymous question from 1995:

Prime Numbers What are prime numbers?

Doctor Ken answered with the definition and a pair of examples:

Hello! A prime number isa positive number that has exactly two factors, 1 and itself. For example, if we list the factors of 28, we have 1, 2, 4, 7, 14, and 28. That's six factors. If we list the factors of 29, we only have 1 and 29. That's 2. So we say that29 is a prime number, but 28 isn't.

As we’ll be seeing in the next two weeks, there are many ways to misstate this definition; every word in the definition matters!

Note that the definition of a prime numberdoesn't allow 1 to be a prime number: 1 only has one factor, namely 1. Prime numbers have EXACTLY two factors, not "at most two" or anything like that.

This is where the word “exactly” comes in. Without it, you could take “has two factors, 1 and itself” as being true for 1, since 1 and itself are both factors and there is no other. (We’ll be seeing next week why we don’t *want* 1 to be a prime number; and the following week, we’ll see why “positive” matters.)

Here are the first few prime numbers: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, etc.

One important feature of prime numbers is that they are hard to predict, and seem almost random – yet they are definitely not! Here are the primes less than 100 on a number line:

Here are all the primes listed above, namely those less than 200:

The farther out you look, the more random they appear. Even here, you can see runs of nearly consecutive primes, and gaps with none.

Here is a 1997 question:

Prime Numbers: 20-30 Dear Dr. Math, What are the prime numbers 20 through 30? My mom can't help me. Thank you, Leah

Doctor Wilkinson answered, starting with the basics:

First of all, you need to be sure you understand what prime numbers are. In fact, if you understand that, you should be able to do this problem without any difficulty. A prime number isa whole number which is not the product of smaller numbers. For example, 14 is not a prime number, because it is 2 times 7. But 3 is a prime number, because the only smaller numbers are 1 and 2, and 3 is not 1 times 1 or 1 times 2 or 2 times 2.

This version of the definition is less formal, but gives the main idea well. We can directly use it to find primes (though not very efficiently).

To see if a number is prime, all you need to do istry the numbers smaller than itand bigger than 1 and divide them into your number.If this ever comes out even, then your number isn't prime. Otherwise, it is. For example take15. If you try dividing it by 2, it doesn't come out even. But if you try 3, it does. 15 is 3 times 5. Soit's not a prime. Now let's look at17. If you try dividing it by 2, it doesn't come out even. If you try 3, that doesn't come out even either. Neither does 4, and neither does 5.

One way to improve efficiency would be to try only *prime* divisors, so we’d skip 4. Why? Because if a number can be divided evenly by 4, then it would have already have been found to be divisible by 2. But we aren’t looking for the best possible way to accomplish the task; we just want Leah to experience what primes are – and maybe discover more about them by doing things that aren’t necessary.

Now you could go ahead and try 6, 7, 8, and so on. But if you noticed when you tried 5, you got a quotient of 3 and a remainder of 2. Now if you try something bigger, you're going to get a smaller quotient. So if it was going to come out even, it would already have come out even when you tried the smaller number, andat this point you can quit, because you now know that17 is prime.

This kind of thinking allows you to decide when to stop: If the quotient is smaller than the divisor, you don’t need to try any larger divisors.

Do you think you can do this for the numbers from 20 to 30? To get you started, I'll point out that 20, 22, 24, 26, 28, and 30 are all evenly divisible by 2, sonone of them is prime.

This suggests other ways to shorten the work, which you can discover as you work. Later, we’ll look into how to test a number to see if it’s prime, and how to make a list more efficiently. But that can wait.

For more details, here is a question from 2003:

Prime, Composite, or Neither? What are prime and composite numbers? I just don't get it.

Doctor Ian answered:

Hi Hillary, Suppose I have 12 items, and Itry to arrange them into a rectangle. I can do this in more than one way: . . . . . . . . . . . . 1 x 12 . . . . . . 2 x 6 . . . . . . . . . . 3 x 4 . . . . . . . .

We could also use \(4\times3\), \(6\times2\), and \(12\times1\), with the same pairs in the reverse order; we’re interested only in the pairs, not the order.

For some numbers, there isonly one rectanglethat I can make. For example, if I have 7 items, I can do this: . . . . . . . But if I try to make more rows, I always have something left over: . . . . . . . . . . . . . . . . . . . . . A number like7 is called 'prime'. In contrast, a number like12 is called 'composite'.

It’s easy to see that prime numbers are special. They can’t be broken down, sort of like atoms in chemistry.

One way to remember this is that something that is'composed'is'put together'from smaller pieces. (For example, we compose a poem from words, and compose a song from notes.)

So **composite** numbers are numbers that are **composed** of other numbers. (And in chemistry, a **compound** is composed of different atoms! That’s related, too.)

On the other hand, **prime**Â means “**first**“, or “most important”; primes are the numbers we start with when we build up other numbers by multiplication – the building blocks of the natural numbers.

In the case of a number like 12, we can put it together in more than one way, using multiplication: 12 = 1 x 12 = 2 x 6 = 3 x 4 But 1 x 12 is hardly like putting something together, is it? So if we ignore ways that include a 1, we see that there are two ways to put together a 12, 12 = 2 x 6 = 3 x 4 and _no_ ways to 'put together' a 7.

So when we say that a prime number is one that has exactly two factors (itself and 1), we are saying that there are *no* “non-trivial” ways to factor it; it can’t be made by “putting together” numbers *not including itself*.

One tricky point is that the number1 is considered to be neither prime nor composite. (Think about why this would be the case.) So while it's tempting to say things like A number is prime if it's not composite. or A number is composite if it's not prime. neither of these is quite true, because 1 isn't composite, but it's also not prime; and 1 isn't prime, but it's also not composite.

We say that the terms “prime” and “composite” are not exhaustive; “composite” doesn’t quite mean “not prime”. More on this, again, next time.

Why do we care about any of this? That's discussed here: Why Study Prime and Composite Numbers? http://mathforum.org/library/drmath/view/57182.html

That was a reference to the following question from 2001:

Why Study Prime and Composite Numbers? My daughter is in Grade 6. She is learning about prime and composite numbers but my husband and I wonderwhy this is taught in school at all. Who uses this in the real world? Why does someone need to know whether a number is a prime number or not?

Doctor Ian had answered that:

Hi Kim, Every time you send a credit card number over the Internet, it gets encrypted by your browser, and theencryption algorithm is based on the theory of prime numbers. At some point, electronic money will become as common as paper money, and _that_ will also be based on the theory of prime numbers. And what's used more in the real world than money?

Encryption is *everywhere* now! And the basic idea behind the common method is that it’s easy to “compose” numbers, but hard to “decompose” them into a product of primes.

For example, say I choose the primes 7127 and 7879. Their product is 56,153,633. I send you this number (or just post it on my website for anyone to use); you use that number, by a method I’ve specified, to encrypt a message; and I then use my separate primes to create a number I can use to decrypt the message. This calculation is easy using the primes themselves, but would be very hard using only their product. On the other hand, anyone who could factor 56,153,633 could decrypt the message; so I’m trusting that it’s too hard for anyone to do quickly enough to take advantage of it. (We’d really use primes with 100 or more digits.)

But that’s all behind the scenes, and you don’t have to know about that math in order to use it. (*Somebody* does have to know it, though!) How might primes be needed *directly* in your own experience? Mostly as a part of other math:

The importance of prime numbers is thatany integer can be decomposed into a product of primes. For example, if you want to know how many different pairs of numbers can be multiplied to get 360, you can start trying to write them down, 1 * 360 2 * 180 3 * 120 4 * 90 5 * 72 6 * 60 checking every single number up to 180, and hope that you don't miss any; or you can decompose 360 into itsprime factors, 360 = 2 * 2 * 2 * 3 * 3 * 5 with the assurance thatevery factorof 360 will be a product of a subset of these prime factors.

Knowing how a number breaks down, like knowing what atoms a chemical is made of, or how the parts of a car fit together, makes it possible to understand it better.

In the example above, you can list the pairs of factors by listing all ways to choose 0, 1, 2, or 3 twos, 0, 1, or 2 threes, and 0 or 1 five to make a factor. This tells you, in fact, that there are \(4\times3\times2=24\) factors of 360 (that is, 12 pairs of factors). The 12 factors listed above are only half of them. (Can you find the other 12?)

(See Counting Divisors of a Number for more on this.)

This kind of analysis is extremely convenient when working withfractions(since prime factorization tells you whichcommon denominatorsare available for any two fractions), when factoringpolynomials... when doing just about anything where integers are involved, really.

For example, if the denominators of two fractions are, say, 2205 and 2100, that is, \(3^2\times5\times7^2\) and \(2^2\times3\times5^2\times7\), we know that the least common denominator, in order to be a multiple of both, has to have 2 twos, 2 threes, 2 fives, and 2 sevens, making it \(2^2\times3^2\times5^2\times7^2=44,100\). We can find the greatest common factor similarly. Of course, since it is hard to find factors of large numbers, another method is needed when the numbers are *really* large.

(See Many Ways to Find the Least Common Multiple for more on this. Also, compare Three Ways to Find the Greatest Common Factor. And don’t forget How Do You Simplify a Fraction?.)

Are prime numbers *necessary*? Not really:

Think of it this way. You don'tneedto learn to multiply, since you can always use repeated addition to solve any multiplication problem, right? If you want to know what 398 times 4612 is, you can just start adding: 398 (1) 398 (2) ---- 796 398 (3) ---- 1194 398 (4) ---- etc. Knowing about multiplicationsaves you time. That's all it does... but that's a lot!

And that’s what primes do most: save time (sometimes centuries, for really big jobs).

Mostly, prime numbers are good for quickly transforming a situation with zillions of possible outcomes into an equivalent situation withonly a handful of possible outcomes. Here is another way to think about it: If you're looking for some needles in a haystack, you can start picking up each piece of straw, checking to see if it's a needle, and then tossing it over your shoulder. Or you canuse a magnetto find the needles right away. In mathematics, prime numbers serve the same function as a really, Really, REALLY big magnet. In short, knowing about prime and composite numbers will save your daughter enormous amounts of time in her later math classes - and possibly over the course of her life, if she goes into a technical field.

Let’s close with a 1998 question from an entirely different perspective:

Prime Numbers in Different Bases Hi, Dr. Math, Here is a question I have for you. It's on prime numbers. Are all prime numbers the samein all bases? If 21 is a prime, are 10101 (in binary), and 15 (in hexadecimal) also primes? I'm taking a course in Assembly Language Programming, and I was wondering if primality as such is related at all to the number system I am using? What would happen, for instance, if I chose as a base a prime number, such as thirteen?

Computers commonly use base 2 (binary) for internal storage of numbers, and represent them in hexadecimal (base 16) to print them out more compactly. Does that affect prime numbers? How can we recognize them when written in those forms?

Writing a number in a particular base means using place values that are powers of the base. For example, 21 in base 10 means \(21_{10}=2\times10^1+1\times10^0=2\times10+1=21\), while 15 in hexadecimal (base 16) means \(15_{16}=1\times16^1+5\times16^0=1\times16+5=21\). They’re different numerals for the same number.

Doctor Mike answered:

Hi Jorge,A prime is a prime no matter which base you use to represent it. On the surface one might think that in Hex you would have 3*5 = 15 as "usual," but it really turns out that 3*5 = F. The example 21 doesn't work too well because it is not prime. The base ten number 37 is better, because it is prime, but its Hex representation is 25, which sort of looks non-prime. Hex 25 is not, however, repeat not, 5 squared.

Whether you write 21 as \(21_{10}\) or as \(15_{16}\), it is still a composite number; in either base, it is \(3\times7\). And whichever way we write 37, it still refers to the same number – even though we are so familiar with numbers like 25 that we automatically think of it as a square. (A similar issue arises with judgments of evenness and oddness; in an odd base, numbers that “look” even to our base-ten eyes may be odd!)

Okay, enough for examples. The fact of being prime or composite is justa property of the number itself, regardless of the way you write it. 15 and F and Roman numeral XV all mean the number, which is 3 times 5, so it is composite. That is the way it is for all numbers, in the sense that if a base ten number N has factors, you can represent those factors in Hex and their product will be the number N in Hex.

And if a number has no factors other than itself and 1 in base ten, that is still true when you write it in another base. It’s the number that counts, not the numeral (the representation of the number).

So, how do you recognize a prime in binary or hexadecimal? The same way, ultimately, as in decimal: Either do a lot of divisions to look for factors, or be sufficiently fluent in the appropriate base that you recognize products (or know the divisibility tests appropriate to that base – which will all be different than in base ten).

Relating to your question about base 13, the base ten number 13 will be represented as "10" in that system, but "10" will still be a prime, because you cannot find two numbers other than 1 and "10" that will multiply together to make "10". I hope this helps you think about primes in other bases.

So a prime base has no effect on primality of numbers written in it, any more than any other base does. It just makes things *look* different.

Just for fun, here are the first 13 primes, written in base 13 (with digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C):

2, 3, 5, 7, 11, 10, 14, 16, 1A, 23, 25, 2B, 32

They don’t all *look* prime to eyes accustomed to base ten, but they are! (Note that the units digit being even doesn’t imply the number is even, when the base is odd.)

Next week, we’ll look at some special cases: 0 and 1. The following week, we’ll consider negative numbers.

]]>We often solve basic trigonometric **equations**; but a recent set of questions dealt with challenging trigonometric **inequalities**, which bring with them a new set of issues. We’ll look at several of those here, which combine trig with polynomials, rational functions, and more. Each will illustrate something new to watch for.

All of these came, over several days in late October, from Amal. Here is the first:

I need to find the values of x that satisfy this inequality within the range [Ï€, 2Ï€], and this is what I’ve got. Not sure if what I’ve done until now is correct, but I don’t know how to continue from this point on.

Â

We need to solve $$\frac{\sin(2x)+2\cos^2(x)-1}{\cos(x)-\cos(3x)+\sin(3x)-\sin(x)}\le2\cos(x)$$ for \(\pi\le x\le2\pi\). (We’ll see that the handwritten interval is wrong, and this is what was intended; that is not important.)

Amal has applied a multiple-angle identity, $$\cos(2x)=2\cos^2(x)-1,$$ to the numerator, and two sum-to-product identities, $$\cos(a)-\cos(b)=-2\sin\left(\frac{a+b}{2}\right)\sin\left(\frac{a-b}{2}\right)\\\sin(a)-\sin(b)=2\cos\left(\frac{a+b}{2}\right)\sin\left(\frac{a-b}{2}\right),$$ to the denominator, then factored and canceled to get $$\frac{1}{2\sin(x)}\le2\cos(x),$$ then correctly found values that lead to equality. But this is an *in*equality!

Doctor Rick answered:

Hi, Amal.

I believe you have correctly found the

four solutions of the associated equationin [0, 2Ï€]. There is a little more work to do in order to solve theinequality.When you multiply through by 2 sin x, you need to

consider the sign of that quantity: if it is negative, then the direction of the inequality must be reversed (replace â‰¤ by â‰¥).In each case, I would then decide where the inequality is true by

sketching the graph of sin(2x)along with the line y = 1/2. You have found the points where the lineintersectsthe sine curve; where, in relation to these, is the sine curvethe line?above

There are several possible approaches to an inequality like this; Doctor Rick is suggesting minimal changes to what Amal has done, which is our usual practice. (I’ll show an alternative method at the end.) This will require considering separate cases to correctly handle the multiplication by the denominator. (There’s at least one other issue he hasn’t yet touched upon.)

Amal replied:

I believe I have made a mistake. The range in which the solutions should be is [Ï€, 2Ï€].

Does that change anything?

On the other hand, I completely ignored the possibility of 2sinx being negative, as you mentioned. My question is now, how do I combine both solutions for when Â½ â‰¤ sin2x and Â½ â‰¥ sin2x?

Doctor Rick answered:

You write:

I believe I have made a mistake. The range in which the solutions should be is [Ï€, 2Ï€]. Does that change anything?

Do you mean that what was written on the paper was incorrect, and you are

interested in the solutions in the interval [Ï€, 2Ï€]? That’s fine, just keep it in mind in what follows.onlyOn the other hand, I completely ignored the possibility of 2sinx being negative, as you mentioned. My question is now, how do I combine both solutions for when Â½ â‰¤ sin2x and Â½ â‰¥ sin2x?

Don’t worry about

combiningsolutions until youhavethe solutions.Under what conditions is 2 sin x < 0? What inequality do you get when 2 sin x < 0, and what do you find for its solution set? (You’ve already got the inequality to solve when 2 sin x > 0.)

Amal said,

Ok now looking at it, since the range isÂ [Ï€, 2Ï€], the inequality has to beÂ 1/2Â â‰¥ sin2x, given that if one plugs any value from the range into 2sinx, it will give a negative value.

Doctor Rick acknowledged:

Good, that’s what I wanted you to see — and it’s why I held off on discussing combining of solutions:

we really have only one inequality to consider.So can you proceed with solving the inequality

1/2 â‰¥ sin(2x), Ï€ â‰¤ x â‰¤ 2Ï€

using the sketching method I suggested, or any other method?

If a different interval had been required, we would actually have to follow through on both cases!

Let’s review is what he has done so far:

Given $$\frac{\sin(2x)+2\cos^2(x)-1}{\cos(x)-\cos(3x)+\sin(3x)-\sin(x)}\le2\cos(x)$$ for \(\pi\le x\le2\pi\), he obtained $$\frac{\sin(2x)+\cos(2x)}{2\sin(2x)\sin(x)+2\cos(2x)\sin(x)}\le2\cos(x)$$ as before, and factored and canceled to get $$\frac{\sin(2x)+\cos(2x)}{2\sin(x)(\sin(2x)+\cos(2x))}\le2\cos(x)\\\frac{1}{2\sin(x)}\le2\cos(x).$$ Then, knowing that since \(\pi\le x\le2\pi\), \(\sin(x)\le0\), so that he could multiply both sides by that, reversing the direction, to obtain $$1\ge4\sin(x)\cos(x),$$ which is equivalent to $$\sin(2x)\le\frac{1}{2}.$$ Equality holds for $$2x=\frac{\pi}{6}+2k\pi\text{ or }\frac{5\pi}{6}+2k\pi\\x=\frac{\pi}{12}+k\pi\text{ or }\frac{5\pi}{12}+k\pi$$ and for \(\pi\le x\le2\pi\), this yields $$x=\frac{13\pi}{12}\text{ or }\frac{17\pi}{12}.$$ This is where he had stopped originally.

Now we’re ready to move beyond that.

Amal responded:

Here’s the sketch I made, and above it the solution.

Now I do have one last question. The solution for this exercise should be (Ï€, 13Ï€/12] âˆª [17Ï€/12,

15Ï€/8) âˆª (15Ï€/8, 2Ï€), according to answer sheet.Where could have I missed that 15Ï€/8?

Looking at a sketch of the graph over \([\pi,2\pi]\), we see that the inequality holds for values of *x* that are not between them.

Doctor Rick answered,

That looks good!

Now, what have webothmissed?One thing we always need to be careful about is

losing (or gaining) roots when we simplify an equation. You canceled (sin 2x + cos 2x) from the numerator and denominator in the equation. What if that quantity equals zero – could that cause problems?When (sin 2x + cos 2x) equals zero, the numerator on the LHS is 0, and the denominator is 0. If we were solving an

equation, I would thus think: OK, it’s not an issue, because any value of x that makes that quantity zero won’t be a solution anyway; the LHS is not a number. And that’s how Ithink — forgetting that this is andid! Itinequalitymatter that any such value of x isdoesnotin the solution set.So now you know what else you need to do.

So, if the problem had been to solve $$\frac{\sin(2x)+2\cos^2(x)-1}{\cos(x)-\cos(3x)+\sin(3x)-\sin(x)}=2\cos(x),$$ the cancellation $$\require{cancel}\frac{\cancel{\sin(2x)+\cos(2x)}}{2\sin(x)\cancel{(\sin(2x)+\cos(2x))}}=2\cos(x)$$ would be innocuous, because the expression being canceled is not zero for the solution values we found. But in the **inequality**, the solution is an **interval** that includes a value we have to exclude.

Amal was now ready to answer the problem:

Ok perfect. So what I added to my solution is sin2x â‰ -cos2x, therefore the only value of x within the range that cannot be a solution is 15Ï€/8.

So we have to exclude \(\frac{15\pi}{8}\) from the solution set because $$\sin(2x)+\cos(2x)=\sin\left(\frac{15\pi}{4}\right)+\cos\left(\frac{15\pi}{4}\right)=-\frac{\sqrt{2}}{2}+\frac{\sqrt{2}}{2}=0and the PHS would be 0/0.$$

Doctor Rick approved:

Good! I was confident that you wouldn’t need more help on this. You now have some ideas that might help with your other problems if any remain unsolved.

I solved sin 2x + cos 2x = 0 in a different way, rewriting it as tan 2x = â€“1. Either way works.

This approach gives $$\sin(2x)+\cos(2x)=0\\\frac{\sin(2x)}{\cos(2x)}+\frac{\cos(2x)}{\cos(2x)}=0\\\tan(2x)=-1\\2x=\frac{3\pi}{4}+k\pi\\x=\frac{3\pi}{8}+\frac{k\pi}{2}$$ and the solutions in our interval are \(\frac{11\pi}{8}\) or \(\frac{15\pi}{8}\). The former is already excluded.

We’ll return to this problem at the end, with both a different approach, and a full solution.

The second problem was submitted immediately after that last one:

Don’t know what else to do besides what I’ve written. Also, the square root of tangent of x confuses me a bit and don’t know what to do with it.

Note that, as is common in some parts of the world, he uses the notation \(\text{tg}(x)\) where I would use \(\tan(x)\), for the tangent. We generally stick with the notation a student uses.

It’s also worth noticing that this time we want the general solution, not just a solution restricted to a particular interval.

Here, as before, he has done nicely in finding zeroes; this time the complicating issue, beyond finding intervals, is not cancelling a factor, but that odd square root. What do we do with that?

I answered (while the first question was still being discussed):

Hi, Amal.

You have correctly found where the LHS is zero, apart from the influence of the tangent.

The latter has an effect only when the tangent is 0, as otherwise âˆštg(x) is a positive number, and you can safely divide both sides by it. But in addition,it affects the domain of the entire inequality, so it will eliminate some parts of the solution you’d find otherwise.

There are three separate issues: the factor \(\sqrt{\text{tg}(x)}\)Â is **never negative**, so it won’t affect the **sign** of the product, which is what matters in an inequality like this; but **its zeros will be solutions**, and it will also prevent some otherwise-solutions from being accepted, because they would not be **in the domain** of the left-hand side.

But so far, he has only found zeroes of the other part, and has not dealt with the inequality.

Now you need to think about the inequality aspect, which you can treat the same way as any

polynomial inequality. Can you show me how you would solve (2x – 1)(x â€“ 1) â‰¤ 0? You can use the same technique here to obtain an inequality in sin(x), and solve that.So, either just show me how you solve the polynomial inequality, or try applying that idea to the sine, and we can discuss whatever you show me.

A **polynomial inequality** like \((2x-1)(x-1)\le0\) can be solved by recognizing that the LHS can only change sign at its zeroes, and either testing the value in each of the intervals between, or by considering the sign of each factor individually. Or, as Amal will do below, it can be solved by considering separate cases: Since the product has to be negative, either the first factor is negative and the second positive, or *vice versa*.

Amal complied:

This is how I solved the inequality, but idk how to apply it to the actual inequality.

(I meant to write the solution as Â½ â‰¤ x â‰¤ 1.)

Yet another way you could solve this would be to recognize that the LHS is a parabola opening upward, so it will be negative between its two zeroes.

However we do it, we have found, replacing \(x\) there with \(\sin(x)\), that \(\frac{1}{2}\le \sin(x)\le1\).

Â I responded:

Good.

I would next

sketch a graph of the sine, over thedomain implied by the radical. What is that domain?At the end you’ll want to consider

what happens when tan(x) = 0, which adds something to the answer.

Here is the graph of the sine, including the interval into which it must fall, and the resulting interval in *x*Â (shaded):

But we still need to deal with \(\sqrt{\text{tg}(x)}\).

Amal finished the solution:

Ok so, I applied Â½ â‰¤ x â‰¤ 1 to sinx, there for if we solve for x, it should be 2Ï€k + Ï€/6 â‰¤ x â‰¤ Ï€/2 + 2Ï€k, but since the “domain” you asked about (which I should’ve referred to it as a restriction) says that x cannot be Ï€/2 + Ï€k (because of tanx), the expression should be 2Ï€k + Ï€/6 â‰¤ x < Ï€/2 + 2Ï€k.

Then if we consider what happens when tanx is 0, we get that x should be Ï€k, so I add it to the solution.

In my own usage, a “restriction” would be a statement in the problem itself restricting the solution to some interval, as in the first problem; here the “restriction” is implied by the domain of the functions involved. But the terminology is not important.

Here is my version of the work: \(\frac{1}{2}\le \sin(x)\le1\) is true for \(\left[\frac{\pi}{6},\frac{5\pi}{6}\right]\) (repeating every period), but the factor \(\sqrt{\text{tg}(x)}\) on one hand **adds in** the solution \(x=k\pi\) because the factor is 0 there, and on the other hand **restricts** the solution to \(0\le x<\frac{\pi}{2}\), where the tangent exists and is not negative, so that the actual solution is the intersection of what we previously found and the shaded regions shown here:

Combining these, we get his answer, which in one period, \([0,2\pi)\), is \(\{0\}\cup\left[\frac{\pi}{6},\frac{\pi}{2}\right)\cup\{\pi\}\).

I concluded:

That looks good. I graphed the LHS and marked (in green) the region in which it is â‰¤0, and it agrees with what we both found:

I would say that the fact that tan(x) can be zero adds 0, Ï€, …, but the

requires that tan(x) â‰¥ 0, which is why the solution stops at Ï€/2, while thedomain of the radicaldomain of the tangentfunctioneliminates Ï€/2.These are not easy problems!

Amal closed:

Makes total sense! And yes, definitely not easy ones.

Thank you for your help.

Amal sent a third problem while the second was being discussed:

This is as much as I can simplify the inequality, but don’t know how to continue.

Also in green is the values of x that will not satisfy the expression.

This must be solved for [0, 2Ï€]

This is closer than the first was to a traditional **rational inequality**, with sinusoids replacing the variable, and he has done a good job putting it into factored form. He first wisely put the numerator in terms of functions of the same angle (using the double-angle formula \(\sin(2\theta)=2\sin(\theta)\cos(\theta)\)), and then found it could be factored (by grouping). He also rewrote the denominator using an angle-sum identity, which turns out to be unnecessary but was not a bad idea. He also found the values of *x* that make the denominator zero, which must be excluded.

I answered:

Hi, Amal.

You’ve done just what I did to start, except that I’m not sure that the change to the denominator helps.

Now that you have it in factored form, I would identify where each of the two factors on top, and the factor on the bottom, is zero, and note where it changes sign.

Then I would do as I do for rational inequalities, and

mark the sign of each factor in these regionson a number line, then find which regions yield anegative or zero (and defined) value for the entire expression. We show a similar method toward the bottom of this article:

Amal responded:

Perfect, I thought of doing something like that but I wasn’t sure when it would change signs.

Here’s my work.

He has reverted the denominator to its original form, and then determined the intervals over which each factor would be positive, negative, or zero. His interesting graph is a circular version of the number line I had suggested, with the green line outside for positive and inside for negative; this works nicely considering the periodic nature of the functions. Here is my version (using a straight line), filling in some details:

- A, \(\displaystyle2\sin\left(\frac{x}{2}\right)-1\) is positive when \(\displaystyle\sin\left(\frac{x}{2}\right)>\frac{1}{2}\), which is when \(\displaystyle\frac{\pi}{6}<\frac{x}{2}<\frac{5\pi}{6}\), so that \(\displaystyle\frac{\pi}{3}<x<\frac{5\pi}{3}\). Thus, it is \(\le0\) in \(\displaystyle\left[\frac{\pi}{3},\frac{5\pi}{3}\right]\).
- B, \(\displaystyle\cos\left(\frac{x}{2}\right)-1\) is positive when \(\displaystyle\cos\left(\frac{x}{2}\right)>1\); that is, it is
*never*positive, but is zero at \(x=0\).Â - C, \(\displaystyle\cos\left(x-\frac{\pi}{4}\right)\) is positive when \(\displaystyle\cos\left(x-\frac{\pi}{4}\right)>0\), which is when \(\displaystyle-\frac{\pi}{2}<x-\frac{\pi}{4}<\frac{\pi}{2}\) so that \(\displaystyle-\frac{\pi}{4}<x<\frac{3\pi}{4}\). Thus, it is negative in \(\displaystyle\left(\frac{3\pi}{4},\frac{7\pi}{4}\right)\); when it is zero, the expression is
*undefined*.

Putting these together on a number line, we can mark up regions where each of the three factors is positive (green), zero (blue), and negative (red), and then mark where the entire LHS is negative or zero, and not undefined (because the denominator is zero, white):

$$\{0\}\cup\left[\frac{\pi}{3},\frac{3\pi}{4}\right)\cup\left[\frac{5\pi}{3},\frac{7\pi}{4}\right)$$

(Note that he accidentally wrote \(\frac{7\pi}{3}\) instead of \(\frac{7\pi}{4}\), which I never noticed until now.)

The quick method, described in the post I referred to, is to mark the locations where any factor is zero (marking whether it makes the LHS zero or undefined); then mark the sign of the LHS, by changing it at each point where it should; and then graph the solution set by including each point and interval as appropriate:

I concluded, summarizing what I just did:

Yes, that agrees with my work.

I found that the

first factor on topchanges sign at Ï€/3 and 5Ï€/3, being positive in the middle; thesecond factoris always negative, except for being 0 at x=0; and thedenominatorchanges sign at 3Ï€/4 and 7Ï€/4, at which points the fraction isundefined, being negative in the middle. Putting it together, I got the same answer you show.

There were more similar problems to come, but these had the most interesting discussions.

I’d like to try solving the first problem in a style similar to what we did in the last one. Given a rational inequality (in trig functions), like our $$\frac{\sin(2x)+2\cos^2(x)-1}{\cos(x)-\cos(3x)+\sin(3x)-\sin(x)}\le2\cos(x)$$ it is standard to first get a zero on the right-hand side and simplify as one big fraction on the left. After Amal’s simplifications (but omitting the cancellation), we have this: $$\frac{\sin(2x)+\cos(2x)}{2\sin(x)(\sin(2x)+\cos(2x))}\le2\cos(x)\\\frac{\sin(2x)+\cos(2x)}{2\sin(x)(\sin(2x)+\cos(2x))}-2\cos(x)\le0\\\frac{\sin(2x)+\cos(2x)}{2\sin(x)(\sin(2x)+\cos(2x))}-\frac{4\sin(x)\cos(x)(\sin(2x)+\cos(2x))}{2\sin(x)(\sin(2x)+\cos(2x))}\le0\\\frac{\sin(2x)+\cos(2x)-2\sin(2x)(\sin(2x)+\cos(2x))}{2\sin(x)(\sin(2x)+\cos(2x))}\le0\\\frac{(1-2\sin(2x))(\sin(2x)+\cos(2x))}{2\sin(x)(\sin(2x)+\cos(2x))}\le0$$

We can cancel \(\sin(2x)+\cos(2x)\), keeping in mind that points where this is zero (namely \(x=\frac{3\pi}{8}+\frac{k\pi}{2}\)) will be excluded; now we have $$\frac{1-2\sin(2x)}{2\sin(x)}\le0$$ The numerator is zero (and changes sign) at \(x=\frac{\pi}{12}+k\pi,\frac{5\pi}{12}+k\pi\), and the denominator for \(x=k\pi\). The sign is positive just above \(x=0\), so it is negative or zero in \(\left[\frac{\pi}{12}+2k\pi,\frac{5\pi}{12}+2k\pi\right]\), and in \(\left(\pi+2k\pi,\frac{13\pi}{12}+2k\pi\right]\), and in \(\left[\frac{17\pi}{12}+2k\pi,2k\pi\right)\).

Here is the number line model:

Here, the green marks correspond to the cancellation, which doesn’t change the sign but makes a hole in the solution set.

In the original problem, we considered only \(\pi\le x\le2\pi\); here we see the full solution for each period (that is, you can add \(+2k\pi\) to each number): $$\left[\frac{\pi}{12},\frac{3\pi}{8}\right)\cup\left(\frac{3\pi}{8},\frac{5\pi}{12}\right]\cup\left(\pi,\frac{13\pi}{12}\right]\cup\left[\frac{17\pi}{12},\frac{15\pi}{8}\right)\cup\left(\frac{15\pi}{8},2\pi\right)$$

Here is a graph of the LHS (red) and RHS (green), with shading showing where red is below green:

The broken lines indicate the values that must be omitted because of the canceled factor; neither Desmos (which I used for this) nor GeoGebra (which couldn’t do the shading) can show the required holes.

]]>