Skip to content

Divisibility and Prime Factorization

Updated · Equations updated; Sections updated; Examples or practice updated; Explanations expanded What changed?
  1. — Equations updated; Sections updated; Examples or practice updated; Explanations expanded

For integers a≠0a\ne0 and bb, the notation a∣ba\mid b means b=akb=ak for some integer kk. If aa divides both bb and cc, it divides every integer combination ub+vcub+vc. This lets us replace large expressions by smaller differences.

Every integer greater than one has a unique factorization into primes, apart from the order of the factors. Divisibility can therefore be checked one prime at a time: a∣ba\mid b for positive integers exactly when every prime exponent in aa is at most the corresponding exponent in bb.

Example. A positive integer nn satisfies n∣3n+14n\mid3n+14. Find all possible nn.

Because n∣3nn\mid3n, subtracting gives n∣14n\mid14. Thus n∈{1,2,7,14}n\in\{1,2,7,14\}. Conversely, every positive divisor of 1414 divides 3n+143n+14, so all four values work.


The greatest common divisor gcd⁡(a,b)\gcd(a,b) takes the smaller exponent of each prime in positive a,ba,b. The least common multiple lcm⁡(a,b)\operatorname{lcm}(a,b) takes the larger. Thus

gcd⁡(a,b)lcm⁡(a,b)=ab.\gcd(a,b)\operatorname{lcm}(a,b)=ab.

Factoring is not always the fastest way to find a GCD. The Euclidean algorithm repeatedly uses

gcd⁡(a,b)=gcd⁡(b,a−qb).\gcd(a,b)=\gcd(b,a-qb).

The common divisors stay the same when a multiple of one number is subtracted from the other.

Example. Find gcd⁡(252,198)\gcd(252,198) and express it as an integer combination of the two numbers.

The divisions are

252=198+54,198=3⋅54+36,54=36+18.252=198+54,\quad198=3\cdot54+36,\quad54=36+18.

The last nonzero remainder is 1818. Substituting backward,

18=54−36=4⋅54−198=4⋅252−5⋅198.18=54-36=4\cdot54-198=4\cdot252-5\cdot198.

Thus the GCD is 1818, with the displayed integer combination.

Bézout’s identity says that such a combination always exists:

au+bv=gcd⁡(a,b)au+bv=\gcd(a,b)

for some integers u,vu,v. In particular, if gcd⁡(a,b)=1\gcd(a,b)=1 and a∣bca\mid bc, then a∣ca\mid c: multiply a Bézout combination of a,ba,b by cc. This is the correct cancellation rule for divisibility.


If n=p1e1⋯prern=p_1^{e_1}\cdots p_r^{e_r}, each positive divisor chooses its exponent of pip_i independently from 0,1,…,ei0,1,\ldots,e_i. Therefore

τ(n)=∏i=1r(ei+1).\tau(n)=\prod_{i=1}^r(e_i+1).

Multiplying the possible prime-power contributions instead of just counting them gives the divisor sum:

σ(n)=∏i=1r(1+pi+⋯+piei)=∏i=1rpiei+1−1pi−1.\sigma(n)=\prod_{i=1}^r(1+p_i+\cdots+p_i^{e_i}) =\prod_{i=1}^r\frac{p_i^{e_i+1}-1}{p_i-1}.

Example. Find the number and sum of the positive divisors of 360360.

Factor 360=23⋅32⋅5360=2^3\cdot3^2\cdot5. Thus

τ(360)=(3+1)(2+1)(1+1)=24,\tau(360)=(3+1)(2+1)(1+1)=24, σ(360)=(1+2+4+8)(1+3+9)(1+5)=15⋅13⋅6=1170.\sigma(360)=(1+2+4+8)(1+3+9)(1+5)=15\cdot13\cdot6=1170.

Divisors also pair as dd and n/dn/d. A positive integer has an odd number of divisors exactly when it is a square, because only a square has a divisor paired with itself.


A positive integer is a perfect kkth power exactly when all its prime exponents are divisible by kk. This turns questions about squares and cubes into remainder calculations on exponents.

Example. Find the smallest positive integer mm for which 360m360m is a square.

The exponents in 360=23⋅32⋅5360=2^3\cdot3^2\cdot5 must all become even. Add one factor of 22 and one factor of 55, giving m=10m=10 and 360m=3600=602360m=3600=60^2. Any successful mm must contain both of those factors, so 1010 is smallest.

If coprime positive integers a,ba,b have a square product, each is a square: no prime is shared, so an odd exponent in one cannot be repaired by the other. The same statement holds for any perfect kkth power.

Example. Find all positive integers nn for which n(n+1)n(n+1) is a square.

Consecutive integers are coprime, so both n=a2n=a^2 and n+1=b2n+1=b^2 would have to be squares. Then

(b−a)(b+a)=1.(b-a)(b+a)=1.

The only nonnegative square solution is a=0,b=1a=0,b=1, which gives n=0n=0 and violates positivity. Thus no positive nn works.

The Euclidean algorithm applies to expressions as well as numerical inputs. The useful move is still subtracting an integer multiple, chosen so that the largest terms cancel. A complicated GCD can collapse to a small constant or a familiar expression.

For positive m,nm,n and integer a>1a>1,

gcd⁡(am−1,an−1)=agcd⁡(m,n)−1.\gcd(a^m-1,a^n-1)=a^{\gcd(m,n)}-1.

If m>nm>n, subtract am−n(an−1)a^{m-n}(a^n-1) from am−1a^m-1 to replace the first exponent by m−nm-n. The common divisors are unchanged. Repeating the subtraction follows the Euclidean algorithm on the exponents, ending at their GCD.

Example. Find gcd⁡(284−1,260−1)\gcd(2^{84}-1,2^{60}-1) without evaluating either large number.

The exponent GCD is twelve, so the expression equals 212−1=40952^{12}-1=4095. The exponent identity is the reason reducing the problem this way is valid; simply taking the GCD of exponents inside an arbitrary expression would not be justified.

A smaller algebraic GCD often controls how prime powers can split across factors. For instance,

gcd⁡(n−1,n+1)=gcd⁡(n−1,2).\gcd(n-1,n+1)=\gcd(n-1,2).

Thus the two factors of n2−1n^2-1 are coprime when nn is even and share only a factor of two when nn is odd. This is often the decisive observation in perfect-power equations.


The divisor-count formula comes from choosing prime exponents independently. Additional conditions simply alter the allowed exponent choices.

If N=∏pieiN=\prod p_i^{e_i}, the number of square divisors is ∏i(⌊ei/2⌋+1)\prod_i(\lfloor e_i/2\rfloor+1), since only even exponents are permitted. More generally, perfect kkth-power divisors use exponents 0,k,2k,…0,k,2k,\ldots. For divisors divisible by M=∏pifiM=\prod p_i^{f_i} with M∣NM\mid N, the available exponent range is fi,…,eif_i,\ldots,e_i, giving ∏i(ei−fi+1)\prod_i(e_i-f_i+1).

Example. Find the number of positive divisors of 360360 that are squares, and the number divisible by twelve.

Use 360=23325360=2^3 3^2 5. A square divisor chooses the exponent of two from {0,2}\{0,2\}, of three from {0,2}\{0,2\}, and of five only as zero. There are four square divisors.

For a divisor divisible by 12=22312=2^2 3, the exponents have respectively two, two, and two choices. Hence there are eight such divisors.

For coprime factor pairs ab=Nab=N, every prime power of NN must go entirely into one factor or the other. If NN has rr distinct prime divisors, there are 2r2^r ordered coprime factorizations. Allowing a prime power to split between the two factors would violate coprimality.


To make an integer divisible by every number in a list, retain the largest required exponent of each prime. In particular,

lcm⁡(1,2,…,n)=∏p≤npep,\operatorname{lcm}(1,2,\ldots,n)=\prod_{p\le n}p^{e_p},

where pepp^{e_p} is the largest power of pp not exceeding nn. This is different from n!n!, which contains many repeated factors that are unnecessary for the divisibility requirement.

If a power of an unknown number must satisfy the divisibility, divide the required exponents by that power and round up.

Example. Find the smallest positive integer mm such that m2m^2 is divisible by every integer from one through twelve.

The required least common multiple is 23325⋅7⋅112^3 3^2 5\cdot7\cdot11. Therefore mm needs prime exponents at least ⌈3/2⌉,⌈2/2⌉,1,1,1\lceil3/2\rceil,\lceil2/2\rceil,1,1,1. The smallest possibility is

m=22⋅3⋅5⋅7⋅11=4620.m=2^2\cdot3\cdot5\cdot7\cdot11=4620.

Each required exponent is forced, so omitting any factor would fail. Adding any other prime would only increase the number.

This “required exponent, then round up” method also handles a smallest multiplier making a number a cube or a smallest denominator clearing several rational expressions.


The Smallest Number with a Given Divisor Count

Section titled “The Smallest Number with a Given Divisor Count”

Suppose NN has exactly dd positive divisors. Its exponents satisfy ∏i(ei+1)=d\prod_i(e_i+1)=d. To minimize NN, use the smallest available primes and place the largest exponents on the smallest primes.

The ordering follows from an exchange: if p<qp<q and a>ba>b, then paqb<pbqap^aq^b<p^bq^a. Thus a minimizing factorization has nonincreasing exponents attached to increasing primes.

Example. Find the smallest positive integer with exactly twenty-four divisors.

List the unordered factorizations of twenty-four into integers greater than one. They give exponent patterns

(23), (11,1), (7,2), (5,3), (5,1,1), (3,2,1), (2,1,1,1).(23),\ (11,1),\ (7,2),\ (5,3),\ (5,1,1),\ (3,2,1),\ (2,1,1,1).

Using the smallest primes in decreasing exponent order gives, respectively,

223, 6144, 1152, 864, 480, 360, 420.2^{23},\ 6144,\ 1152,\ 864,\ 480,\ 360,\ 420.

The smallest is 360=23325360=2^3 3^2 5. Its divisor count is 4⋅3⋅2=244\cdot3\cdot2=24. The complete factorization list and exchange argument prove that a smaller integer cannot work.

The divisor-count equation is multiplicative, so treating twenty-four as a sum of exponent contributions would be incorrect. Each new prime adds a new factor to the divisor count.


A positive integer is perfect when the sum of its proper positive divisors equals the number itself. Equivalently, σ(N)=2N\sigma(N)=2N. The divisor-sum formula lets us verify such conditions without listing every divisor.

If 2p−12^p-1 is prime, then

N=2p−1(2p−1)N=2^{p-1}(2^p-1)

is perfect. The two displayed factors are coprime, so their divisor sums multiply:

σ(N)=(1+2+⋯+2p−1)(1+(2p−1))=(2p−1)2p=2N.\sigma(N)=(1+2+\cdots+2^{p-1})(1+(2^p-1)) =(2^p-1)2^p=2N.

For p=3p=3 this gives twenty-eight, and for p=5p=5 it gives four hundred ninety-six. The prime condition matters; a composite second factor has additional divisors and changes the sum.

This is a construction of perfect numbers, not a proof that every number of the displayed shape works. A formula containing a primality hypothesis must keep that hypothesis when used in examples.


Factorials, Coprimality, and New Prime Divisors

Section titled “Factorials, Coprimality, and New Prime Divisors”

For n≥2n\ge2, no prime at most nn divides n!+1n!+1, because it divides n!n! and cannot also divide the difference one. Therefore every prime divisor of n!+1n!+1 exceeds nn. This proves there are arbitrarily large primes, but does not prove n!+1n!+1 itself is prime.

Example. Prove that n!+1n!+1 and (n+1)!+1(n+1)!+1 are coprime for every positive integer nn.

Subtract (n+1)(n+1) times the first expression from the second. Their common divisors must divide −n-n, so

gcd⁡(n!+1,(n+1)!+1)=gcd⁡(n!+1,n).\gcd(n!+1,(n+1)!+1)=\gcd(n!+1,n).

Since nn divides n!n!, any common divisor of n!+1n!+1 and nn divides one. The GCD is therefore one.

The proof combines algebraic subtraction with a simple divisibility fact. This is often more effective than trying to factor expressions involving factorials.


If positive integers a,ba,b are coprime, then a+ba+b is coprime to abab. A prime dividing both would divide one of a,ba,b and then, from the sum, the other, contradicting coprimality.

This lets us cancel an entire product in a divisibility condition even when the numbers themselves are unknown.

Example. Coprime positive integers a,ba,b satisfy a+b∣a2+b2a+b\mid a^2+b^2. Find all possible pairs.

Subtract the divisible expression (a+b)2(a+b)^2 to obtain a+b∣2aba+b\mid2ab. Since gcd⁡(a+b,ab)=1\gcd(a+b,ab)=1, the sum divides two. Positivity gives a+b≥2a+b\ge2, so the sum is exactly two and a=b=1a=b=1.

The pair satisfies both the coprimality and divisibility requirements. Without coprimality, many scaled examples would remain, so that hypothesis is doing essential work.


The Fibonacci numbers satisfy

gcd⁡(Fm,Fn)=Fgcd⁡(m,n).\gcd(F_m,F_n)=F_{\gcd(m,n)}.

The proof combines two simple recurrence facts. First, consecutive Fibonacci numbers are coprime, since applying the recurrence repeatedly reduces their GCD to gcd⁡(F1,F0)=1\gcd(F_1,F_0)=1.

Second, the addition identity

Fn+r=Fn+1Fr+FnFr−1F_{n+r}=F_{n+1}F_r+F_nF_{r-1}

follows by induction on r≥1r\ge1. Reducing it modulo FnF_n and using the coprimality of Fn+1,FnF_{n+1},F_n gives

gcd⁡(Fn+r,Fn)=gcd⁡(Fr,Fn).\gcd(F_{n+r},F_n)=\gcd(F_r,F_n).

Thus the Euclidean algorithm on the indices is mirrored by a Euclidean algorithm on the Fibonacci values. The endpoint with equal indices or a zero index supplies the claimed formula.

For example, gcd⁡(F84,F60)=F12=144\gcd(F_{84},F_{60})=F_{12}=144. The two original Fibonacci numbers can be very large, but their common divisor is controlled by the much smaller index calculation.

This is a useful general contest habit: when a sequence has an addition identity, check whether it reduces a GCD just as exponent subtraction did for an−1a^n-1. The recurrence may provide a divisibility structure that is invisible from the first few numerical terms.


Reconstructing Numbers from Their GCD and LCM

Section titled “Reconstructing Numbers from Their GCD and LCM”

If positive integers have GCD gg, write them as a=gx,b=gya=gx,b=gy with gcd⁡(x,y)=1\gcd(x,y)=1. Their LCM is then gxygxy. Thus prescribing LCM LL reduces the problem to coprime factor pairs xy=L/gxy=L/g.

This requires g∣Lg\mid L. When it holds, each full prime power of L/gL/g must be assigned entirely to one of x,yx,y. The condition is stronger than simply asking for any factor pair.

Example. Positive integers a,ba,b have GCD twelve and LCM four hundred twenty. Find the smallest possible value of a+ba+b.

Write a=12x,b=12ya=12x,b=12y. Then xy=35xy=35 and x,yx,y are coprime. Up to order, the possibilities are (1,35)(1,35) and (5,7)(5,7). Their corresponding sums are 432432 and 144144.

The minimum is therefore 144, attained by sixty and eighty-four. Checking gives GCD twelve and LCM four hundred twenty, so the candidate meets both requirements.

A fixed product generally favors factors near its square root when minimizing a sum, but the coprimality condition restricts which near factors are admissible. Listing the coprime factor pairs supplies the necessary completeness argument instead of relying only on a continuous AM–GM bound.