Remove each prime power as soon as it is found, and stop trial division once the remaining value has no possible smaller factor:
def divisors(n: Int): Int = {
  require(n >= 1)
  var remaining = n
  var factor = 2
  var result = 1
  while (factor.toLong * factor.toLong <= remaining.toLong) {
    var exponent = 0
    while (remaining % factor == 0) {
      remaining /= factor
      exponent += 1
    }
    result *= exponent + 1
    factor += 1
  }
  if (remaining > 1) result *= 2
  result
}
At an outer-loop boundary, write , where is the product of the prime powers already removed. The invariant states that result is , every prime divisor of is smaller than factor, and remaining has no prime divisor smaller than factor. Thus if factor divides remaining, it is prime; a composite factor would have a smaller prime divisor, contrary to the invariant.
During the inner loop, with fixed, . Each division removes one copy, so the positive remainder strictly decreases and supplies an inner-loop variant. On leaving the inner loop the complete power has been removed; multiplying the result by exponent + 1 uses part (d) and reestablishes the outer invariant after advancing factor. The outer factor increases and can never exceed the original while its guard holds, proving termination.
At exit, a remainder greater than one must be prime: a composite remainder would have a prime factor no larger than its square root, which would still be smaller than factor. It therefore contributes one final factor of two. A remainder of one contributes nothing. The algorithm returns using constant auxiliary space and no array. The widened multiplication in the loop guard prevents an Int overflow in the square test.
Perfection quotient Created 2026-10-20 Updated 2026-10-25
The ratio of the sum of the positive divisors of a positive integer to that integer. For coprime , the ratio is multiplicative because the divisor function is multiplicative. The contribution of a prime power is , so a prescribed quotient can be searched through its remaining numerator and denominator.
Pollard's p-1 algorithm 2026-10-31
For an integer to be factored, John Pollard's method chooses an integer coprime to and an exponent divisible by many small prime powers. Compute by modular exponentiation and the Euclidean algorithm. If , it is a proper factor. If a prime divisor of has , Fermat's little theorem ensures ; success requires some other prime divisor not to divide . Common choices are and . The method exploits a smooth , rather than a small factor itself.
For , every permutation of order of a permutation in is one full cycle if and only if is a prime power. If , all lengths in its disjoint cycle decomposition divide , and their least common multiple is their maximum. One cycle therefore has length and uses every symbol. If has more than one prime divisor, write with coprime by separating one full prime-power factor from the others. Since , disjoint cycles of lengths and fit inside . Their product has order of a permutation , but is not a full cycle.
For unit-modulus prime values, pretentious distance is the Euclidean metric on the finite vectors . On whole arithmetic functions it is only a pseudometric: it sees neither values on prime powers nor primes above the cutoff. Even for every cutoff, the functions one and have distance zero but differ on nonsquarefree integers. The norm representation proves the triangle inequality and identifies exactly the quotient on which separation holds.
Let be a complete discrete valuation ring of residue characteristic of a field , with maximal ideal , and let be a one-dimensional formal group law over . Its multiplication series is . If , the invertible morphism criterion for formal group laws constructs its inverse with coefficients in . Both formal power series converge on , since their coefficients are integral and the powers of an element of tend to zero. Their compositions are the identity there. Thus multiplication by is bijective, including when and is odd. Every finite-order element of consequently has order of a group element equal to a prime power with prime .
Principal-unit group of a mixed-characteristic local field Created 2026-10-03 Updated 2026-10-14
If is finite of degree , then as a topological abelian group
where is the finite group of all roots of unity in whose orders are prime powers dividing a power of .
Second Chebyshev function Created 2026-09-28 Updated 2026-10-14
The Second Chebyshev function is the partial sum of the Von Mangoldt function up to a real cutoff :
For example, , , and . At the jump has size ; between and no new prime power greater than one enters the sum. In contrast, the Chebyshev theta function stays at .
There is also an exact connection with the least common multiple. For , each prime number occurs to the highest exponent for which , both in that least common multiple and in the accumulated Von Mangoldt function weights. Thus
This explains the value at : the least common multiple is . The Chebyshev theta function instead gives the natural logarithm of the primorial . The additional prime powers retain the highest required multiplicities.
Why is this useful for the distribution of prime numbers? The Prime number theorem has the equivalent forms
where is the prime-counting function and denotes asymptotic equivalence. Thus an arithmetic function defined using prime factorization has average weight tending to one over long initial intervals of the positive integers. These are substantive asymptotic equivalences, not consequences of the definitions or the Von Mangoldt divisor identity alone. [ref]
The elementary reason the two Chebyshev functions have the same leading behavior is that their difference is small compared with . Every additional prime power has base , and for each such prime number its total extra weight is at most . There are at most such bases, so
This transfers to , or conversely, once either is established. Partial summation then relates the Chebyshev theta function to the prime-counting function. The estimate controls the extra prime powers; proving the leading value itself is the harder Prime number theorem problem.
Sum-of-divisors function Created 2026-10-03 Updated 2026-10-20
The sum-of-divisors function adds all positive integer divisors of a positive integer, including the number itself:
It is the divisor sum of the identity arithmetic function , so under Dirichlet convolution. Both factors are multiplicative functions, hence so is the sum-of-divisors function. The notation distinguishes it from other weighted divisor sums. [ref]
For a prime number and a nonnegative exponent , the positive integer divisors of the prime power are precisely . Their finite geometric series gives
For example, . For a prime factorization with distinct prime numbers and positive exponents , multiplicativity gives
For , this is an empty product, equal to . [ref]
The distributive property makes the formula especially beautiful: choosing one term from each factor produces each positive integer divisor exactly once, by the fundamental theorem of arithmetic. For , the choices form a three-by-two grid with entries , where and . Adding its rows gives
The divisor function counts six cells; the sum-of-divisors function adds their six values. Once the prime factorization is known, the product formula avoids testing every candidate integer divisor. Shared prime factors require care: , so the sum-of-divisors function is not a completely multiplicative function.
Figure 1.
The sum-of-divisors function for : each grid entry is a positive integer divisor, and the weighted total is
. Details.
Subtracting the number itself gives the proper-divisor sum . Comparing with distinguishes perfect numbers, deficient numbers, and abundant numbers. For , ; for , . Both are perfect numbers. The calculation makes a deficient number, while makes an abundant number. These comparisons turn the sizes of integer divisors into a classification of positive integers. [ref]
Figure 2.
The proper-divisor sum for : perfect numbers lie on , deficient numbers below it, and abundant numbers above it
. Details.
This connection is ancient: Euclid's Elements, Book IX, Proposition 36, constructs a perfect number by multiplying the last term of by their sum, when that sum is a prime number. In modern notation, put and , with and a prime number. The sum-of-divisors function proves the construction immediately:
Consequently the proper-divisor sum is . Taking produces the perfect numbers . [ref]
Total number of prime factors Created 2026-10-06 Updated 2026-10-13
The total number of prime factors counts every occurrence of a prime factor in the prime factorization of a positive integer . Equivalently, it adds the prime valuations:
One may also write over all prime numbers, since only finitely many prime valuations are nonzero. The empty sum gives . By contrast, the prime omega function has and counts distinct prime factors. [ref]
Expanding into shows , whereas and . The same calculation for the comparison examples gives
The total number of prime factors agrees for and , although their prime supports of an integer differ. Meanwhile and have the same radical of an integer and prime omega function, but different values of the total number of prime factors. These examples show exactly which information each arithmetic function forgets.
Figure 1.
One box per prime factor occurrence: the total number of prime factors counts boxes, the prime omega function counts groups, and the radical of an integer multiplies one prime number from each group
. Details.
The total number of prime factors is a completely additive arithmetic function:
The proof is that multiplication adds each prime valuation, , and summing preserves that equality. No coprimality condition is needed. For example, and both have total number of prime factors three; their product has six. By comparison, the prime omega function is only an additive arithmetic function: here .
There is a useful way to see the total number of prime factors as a count of elementary building blocks: any expression of as a product of prime numbers has exactly factors, by the fundamental theorem of arithmetic. Equivalently, every factorization tree for has leaves. Repeated prime factors increase this count without introducing new kinds of prime number. The difference is the existing excess prime-factor multiplicity:
Every summand is nonnegative, so if and only if is a squarefree integer, including . In particular, a prime power with has , and .
Historically, Hardy and Ramanujan's 1917 paper explicitly separated the prime omega function from the total number of prime factors, writing them as and , respectively. Their example has counts three and six. That distinction let them compare two measures of how an integer is built from prime factors. [ref]
Trial division 2026-10-14
Trial division searches for divisors of an integer by testing candidate divisions. For primality testing of an integer , testing the prime numbers up to suffices: any composite number has a prime factor in that range. After finding a prime factor, repeated division removes its prime power, and testing the remaining quotient gives an elementary integer factorization method. This is useful for small inputs, but the number of candidates can grow rapidly with the input's digit count.
Factor a positive integer while multiplying the exponent-plus-one contributions to its divisor count. After removing all prime factors below the current trial factor, a trial factor that divides the remainder must itself be prime. Remove its full power and advance. Once the trial factor's square exceeds the remainder, any remainder greater than one is prime and contributes a factor two. The invariant separates the original integer into removed prime powers and the remaining coprime factor; no factor array is necessary.
Unitary divisor 2026-10-20
A divisor of a positive integer is unitary when . Each prime power in the prime factorization of must therefore be included in completely or omitted completely. Consequently, the sum of the -th powers of unitary divisors is .
Von Mangoldt divisor identity Created 2026-09-24 Updated 2026-10-14
For every positive integer , the divisor sum of its Von Mangoldt function weights recovers its natural logarithm:
The sum runs over the positive integer divisors of . For , its only term is . Equivalently, if and is the constant-one arithmetic function, then , where is Dirichlet convolution. [ref]
For , the positive integer divisors are . Only contribute:
Thus the vanishing of loses no information here: the divisor sum retrieves both copies of the prime factor from the integer divisors and .
Figure 1.
The Von Mangoldt divisor identity assembles from three nonzero divisor weights
. The six positive integer divisors of appear in increasing order. Blue bars contribute at and ; the orange bar contributes at . The remaining three weights are zero. The adjacent stacked bar shows the total . Details.
Proof outline: by the fundamental theorem of arithmetic, write with distinct prime numbers and positive exponents . Among the positive integer divisors, the ones with nonzero Von Mangoldt function weights are exactly . Consequently
The natural logarithm turns the prime factorization product into a sum, and the prime powers greater than one supply exactly the required multiplicities.
Von Mangoldt function Created 2026-09-24 Updated 2026-10-13
The Von Mangoldt function assigns a natural logarithm weight to each positive power of a prime number. For a positive integer ,
Here and throughout the Chebyshev functions, means the natural logarithm. In particular, : the exponent must be positive, even though the convention in prime power allows exponent zero. The support of a function of therefore consists precisely of the prime powers greater than one. [ref]
For example, and , whereas . A composite number can have a nonzero weight: has just one distinct prime factor. But has two distinct prime factors, so its weight is zero. At the weight is , not . This choice lets successive powers record successive copies of the same prime factor in the Von Mangoldt divisor identity.
The Von Mangoldt function is useful because it connects two views of the prime numbers: the prime factorization of an individual integer, through a divisor sum, and the accumulated weights below a cutoff, through the Second Chebyshev function. The latter turns questions about the distribution of prime numbers into questions about a partial sum of an arithmetic function.