A quick way, say in a minute, to deduce whether $1037$ is a prime number

4.6k Views Asked by At

So with $1037 = 17 \cdot 61$, is there a fast method to deduce that it's not a prime number?

Say $1037 = 10^3+6^2+1$. Does $a^3 + b^2 + 1$ factorize in some way?

As part of their interviews, a company is asking whether a number is prime. I have never studied number theory, and I am not aware of a strategy for this apart from polynomial factorization.

I am guessing that for a number they give you, it would have to not be prime, as the only way to see that a number is a prime by hand is to test all primes below $\sqrt{N}$.

11

There are 11 best solutions below

5
On BEST ANSWER

There are various methods for deciding primality, some probabilistic (the result is not sure but the more you run the algorithm the more securely you know the answer) and there are deterministic methods (they decide for sure). Altough all of these working efficiently on numbers that are way greater than $1037$.

With numbers of this size checking all numbers seems to be the most efficient way. There of course are some special cases but if you get a number of this size you should go about checking if it is even (easy), divisible by $3$ (the digitsum is divisible by $3$) by $5$ (ends with $0$ or $5$) and so on. If you have a calculator at hand it wouldn't take longer than a minute since $\sqrt{1037}\approx 32$ so you only have to check primes up to $31$.

They surely do not mean tests like these but I would like to add some links for the sake of completeness

Probablilistic test is the so called Miller-Rabin test.

And for deterministic Pollards $p-1$ and Lenstras elliptic curve factorisation is a fast and efficient one.

Even difference of squares can work fine:

$N$ is to be factored, find a $b^2$ such that $N+b^2$ is a square, say $a^2$ and then

$$ N+b^2=a^2 $$ so $$ N=a^2-b^2=(a-b)(a+b) $$

1
On

I suspect the interviewer is more interested in your approach to answering the question than in the speed of your mental arithmetic. As a practical approach, I would rule out 2,3 and 5 as factors immediately and then use the calculator on my phone to check divisibility by other small primes. For 1037 you only need to check primes up to 31. But the most impotant thing is to talk through what you are doing and why you are doing it.

18
On

$u\mid v$ is read as "$u$ divides $v$" and $u\nmid v$ is read as "$u$ does not divide $v$."


Obviously $2\nmid 1037$ since it has an odd last digit.

By the "Divisibility by $3$ Rule," it follows that $3\nmid 1037$ since $3\nmid 1+0+3+7=11$.

Obviously $5\nmid 1037$ since the last digit is not $0$ nor $5$.

If $7\mid 1037$ then $7\mid 1037-7=1030$ but $1030=103\times 10$, and $103$ is prime and $7\nmid 10$.

If $11\mid 1037$ then $11\mid 1037-77=960$ but $960=96\times 10$ and $11\mid 99$ so $11\nmid 96$ since it is off by a remainder of $3$ (and obviously $11\nmid 10$).

Try for $13$ this time, and then for $17$. You will see that it works for $17$, which indicates that $17\mid 1037$ and $1037$ is not prime.


You can try this method for all numbers, and you only need to try the first prime numbers less than the square root of the number you are testing with; for example, say you don't know if $61$ is a prime number. Then, apply this method.

Now, $64=8^2$ so $\sqrt{61}$ is pretty close to $8$. And since $7^2=49<61$, then all you need to do is see if $2,3,5$ or $7$ divide $61$. If they don't, then $61$ is prime (which it is).

This method does not have an official name, so it might as well be called a "trial divisibility check" by primes. Thanks to users that commented below who corrected me as I thought this method was the following.

A well known method is the "Sieve of Eratosthenes."


Tip:

A good number of primes to remember off the top of your head is all of the primes up to $127$. This has helped me, and $127$ is a pretty special number. There are many good properties about $127$; for example, $127$ is a Mersenne prime (a prime of the form $2^p-1$ for prime $p$), and it is the $31$st prime number, $31$ also being a Mersenne prime.

If you want to remember more prime numbers after $127$, you can. (I did all the way up to $383$, so it is possible.)


Apologies if this answer is primarily opinion-based.

3
On

You're not likely to get even a moderately large random number to factor. In addition to the tests in the other answers, it might help (and it's cool to know) the test for $11$ - calculate the alternating sum of the digits and look for $0$.

At the next level, the fact that $1001 = 7 \times 11 \times 13$ means you can test for divisibility for all of those by calculating the alternating sum of three digit blocks, then just testing the three digit result.

Finally, $91$ is the only number less than $100$ that "looks like a prime" but isn't. That's because the evens, multiples of $3$ and $5$, $77$ and $49$ are clearly composite. The others are the numbers that look like primes.

0
On

If you are confident with powers of 2, note that:

$$1037=2^{10}+13=2^{10}+2^4-3$$

If we are to have an expansion of the form $(a+b)(c+d)$, we can be sure that a 1 and 3 are involved, with one of them negative, that $2^4$ is involved and by extension $2^6$ to multiply together to make $2^{10}$.

The trick is to notice that:

$$ 2^6 = 2^22^4=4\cdot2^4 $$

and so

$$ 2^6-3\cdot2^4=2^4 $$

From which we can deduce that:

$$ 1037 = (2^6-3)(2^4+1) = 61\cdot17 $$

This can be extended into the general relation:

$$ 2^a + 2^b -3 = (2^{a-b}-3)(2^b+1) $$

when $a-2b=2$

0
On

As others pointed out, you really have to check divisibility by primes between 7 and 31. These are 7, 11, 13, 17, 19, 23, 29, 31. If I were to check divisibility of a number around 1000 by these primes by hand as fast as possible, I would try that directly for the lower ones:

7*150 = 1050, 1050 - 1037 = 13, 13 mod 7 != 0

11*100 = 1100, 1100 - 1037 = 63, 63 mod 11 != 0

13*100 = 1300, 1300 - 1037 = 263, 263 mod 13 != 0 (260 mod 13 = 0)

And then look for a suitable candidates for the larger ones. Suitable candidate must be a prime or a product of primes larger than 5:

17*y = 1037 => last digit of y must be 1 => candicates are: 61,71 -> bingo

(the following is not necessary for 1037, but has to be done for a similar number like 1087)

19*y = 1037 => last digit of y must be 3 => candicates are: 53 -> (53*20 - 53 = 1007) too small

23*y = 1037 => last digit of y must be 9 => candicates are: 49(7x7) -> (23*50 - 23) too large

29*y = 1037 => last digit of y must be 3 => candicates are: 43 -> (43*29 > 40*30 = 1200) too large

31*y = 1037 => last digit of y must be 7 => candicates are: 37 -> (31*37 > 30*38 = 1140) too large

0
On

It's not divisible by $2$ (last digit), $3$ (digit sum) or $5$ (last digit).

It's divisible by $7$ iff $(1037-7)/10=103$ is, so iff $(103+7)/10=11$ is, so it's not divisible by $7$.

It's not divisible by $11$ (sum of even digits $\neq$ sum of odd digits).

It's divisible by $13$ iff $(1037+13)/50=21$ is, i.e. it isn't.

It's divisible by $17$ iff $(1037-17)/20=51$ is. $51=3\times 17$, so we have a winner.

1
On

As others have noted, you only need to check primes up to 31. Of course that'll take a while if you have to do it by long division - here's a few shortcuts.

2: The last digit isn't even, so obviously 1037 isn't divisible by 2.

3: The sum of the digits is 11, which isn't divisible by 3, so 1037 isn't divisible by 3.

5: The last digit isn't 5 or 0, so 1037 isn't divisible by 5.

7: If 1037 were divisible by 7, so would 1030. If 1030 were divisible by 7, 103 would be too. If 103 were divisible by 7, so would 110, which is $2 \cdot 5 \cdot 11$ and is therefore not divisible by 7. So 1037 isn't divisible by 7.

11: $1 - 0 + 3 - 7 = -3$, which is not divisible by 11, so 1037 isn't divisible by 11.

13: If 1037 were divisible by 13, then $1050 = 1037 + 13$ would also be. If $1050$ were divisible by 13, $105$ would be too. But $105 = 3 \cdot 5 \cdot 7$, so it isn't divisible by 13, so neither is 1037.

17: 1037 is divisible by 17 only if $1037 - 17 = 1020$ is. 1020 is divisible by 17 only if $102$ is. $102 = 2 \cdot 51 = 2 \cdot 3 \cdot 17$, so it is divisible by 17, so 1037 is divisible by 17, so 1037 isn't prime.

Note: These approaches don't do a good job of factoring - it's a bit tricky to unwind that last argument to figure out what $1037/17$ is. But if the question is just "is it prime", this should work fine.

0
On

Without using rarely taught divisibility tricks...

"If it were divisible by $2$ or $5$ we would see that immediately and it isn't. Dividing by $3$: leaves $13$, leaves $17$, which is not divisible by $3$. Dividing by $7$: leaves $3$, leaves $-2$, leaves $13$, which is not divisible by $7$. Dividing by $11$: Well, $99$ leaves $4$, $47$ is not divisible by $11$. Dividing by $13$: Hmm... $8$ times $13$ is $80+24 = 104$ and $-10+7 = -3$ is not divisible by $13$. Dividing by $17$: Try $6$: $17 \cdot 6 = 60+42 = 102$, leaving $17$, which is divisible by $17$, so $1037$ is not prime. Also, $17$'s cofactor is $61$."

Explanation:

"Dividing by $3$: leaves $13$, leaves $17$, which is not divisible by $3$." $10/3$ has remainder $1$, now append the next digit, $13$. $13/3$ leaves remainder $1$, now append the next digit, $17$, not a multiple of $3$.

"Dividing by $7$: leaves $3$, leaves $-2$, leaves $13$, which is not divisible by $7$." $10/7$ leaves remainder $3$, appending gives $33$ which is $2$ less that $35$, a multiple of $7$, then $-20+7 = 13$, not divisible by $7$.

"Dividing by $11$: Well, $99$ leaves $4$, $47$ is not divisible by $11$." Rather than go at the first two digits, go at the first three. $103$ is barely larger than $11 \cdot 9$, leaving remainder $4$. Appending the next digit, we have $47$, which is not divisible by $11$.

"Dividing by $13$: Hmm... $8$ times $13$ is $80+24 104$ and $-10+7 = -3$ is not divisible by $13$." Again go after the first three digits. Since one-eighth is between $0.12$ and $0.13$, $13\cdot 8 = 80 + 24 = 104$ should be a little over $100$. We overshoot by $1$, meaning $1040$ is divisible by $13$. Then the gap between $1040$ and $1037$, $-3$ is not divisible by $11$.

An entirely different way to go on $13$: A deck of cards is $52$ cards in $4$ suits of $13$ cards, so $52$ is a multiple of $13$ and $5$ nearly evenly divides $103$, $20$ times ($100/5 = 20$, which is usually a well-known currency fact). Then $52 \cdot 20$ = $1040$ ("${}\cdot 20$" means double, then append a zero), which is $3$ too large, but $-3$ is not divisible by $13$.

"Dividing by $17$: Try $6$: $17 \cdot 6 = 60+42 = 102$, leaving $17$, which is divisible by $17$, so $1037$ is not prime. Also, $17$'s cofactor is $61$." It helps to know $1/6 = 0.16666\dots$, so $6\cdot 16$ and $6 \cdot 17$ are around $100$. Then $17 \cdot 6 = 60 = 42 = 102$. From the first three digits, $103 - 102 = 1$, append the last digit, and see $17$, which is definitely divisible by $17$.

One thing that happened a couple of times and that is useful to know. You can be a little sloppy in your divisions. You don't have to get each of them exactly right, you just need to leave a remainder small enough to work with.

For instance, suppose for divisibility by $17$ we tried $7$ first. $17 \cdot 7 = 70 + 49 = 119$, overshooting by $16$. Either we notice that $16 $ is large enough that starting with $6$ would leave the smallest remainder, or we stick with it. We have $-16$ and the next digit is $7$, so we want to know if $-160+7 = -153$ is divisible by $17$. Adding $170$, which is close to the right magnitude and will make things small and positive, we get $17$, and are done again.

2
On

Yes, as suggested we could check the primes up to $\sqrt{n}$. The rest is just luck. For example, the primes up to $\sqrt{1037}\approx 32.2$ are: $$3,5,7,11,13,17,19,23,29,31.$$ Note that the factor $17$ is almost equidistant from the two ends, though checking from the left is indeed easier and faster.

Now consider $1081=23\cdot 47$. The primes up to $\sqrt{1081}\approx 32.9$ are the same: $$3,5,7,11,13,17,19,23,29,31.$$ This time it is easier and faster to start checking from the right.

Question: Is $2021$ prime? Hint: Try right hand approach.

0
On

Clearly 2 and 5 do not divide 1037. To check non divisibility by 7, 11 and 13 note 037 -1 = 36 is not divisible by any of thesee. The smallest number to check by long division is 17 It works