Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

My understanding of mathematics is poor, although I'm trying to improve it, so I hope you will forgive me for asking a rather basic question.

I've written a computer code that prints the prime factors of a natural number. It works well. For instance, for the input $72$ it prints $2 \times 2 \times 2 \times 3 \times 3$. On youtube I saw somebody calculate the input $-72$ to $-1 \times 2 \times 2 \times 2 \times 3 \times 3$, so I adjusted my code to accept all whole numbers. But now I'm wondering what to do if the input is $0$.

Should I simply return $0$ (or $1$)? Should I refuse the input?

I tried some online prime factor calculators to see what would happen, but they either ignored/refused input of non-natural numbers, or, in one case, crashed my browser :-)

share|improve this question
1  
This is the Fundamental Theorem of Arithmetic. Look at the prime factorization results from WA. Regards –  Amzoti Jan 31 '13 at 17:30
add comment

1 Answer

up vote 5 down vote accepted

Positive integers have a prime factorization (i.e., can be written as a product of zero or more factors, all of which are prime numbers.) You may already have a problem with the input $1$ as it does not have any prime factors (while writing $1 = 1$ just like $17=17$ might seem to imply that $1$ is prime). Prepending a factor of $-1$ for negative input is already a trick, as $-1$ is not a prime either. (In the ring of integers, these two exceptions $1$ and $-1$ are the so-called units). Technically, $0$ is a multiple of any prime, but it des not have a prime factorization. So before you start outputting $0 = 0\times 2\times 3\times 5$, I suggest you just output the non-factorization $0=0$ (as you would also output $-1=-1$ and $1=1$),

share|improve this answer
    
One could say that $1$ does not have any prime factors but does have a prime factorization, but $0$ doesn't have a prime factorization. –  Michael Hardy Jan 31 '13 at 18:07
    
@MichaelHardy Yes, I wanted to imply that - but even $1$ poses the "problem" to write down the empty product –  Hagen von Eitzen Feb 1 '13 at 7:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.