Skip to content

IntegerExponent ​

The largest kk with bk∣nb^k \mid n — the bb-adic valuation of nn as an integer.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageIntegerExponent!
IntegerExponent(n, b)the multiplicity of bb in nn
SymPymultiplicity(b, n)
IntegerExponent(n)base 10
Typed signatures
TypePackageApplies
(number, number?) -> integer | numbernumber-theoryalways

Domain: Number theory

Details
  • Integers only: a rational's pp-adic valuation is AdicValuation's, over AdicNumeral.
  • n=0n = 0 has every power of bb as a divisor, so IntegerExponent(0, b) is PositiveInfinity.
  • bb need not be prime — IntegerExponent(n, 6) is the largest kk with 6k∣n6^k \mid n, not the 2-adic or 3-adic valuation.

Examples

3 more kept as data, checked against the oracles
Basic #

2000=53⋅162000 = 5^3 \cdot 16

live ↗
InIntegerExponent(2 000,5)\mathrm{IntegerExponent}(2\,000, 5)Out33

base 10 by default

live ↗
InIntegerExponent(2 000)\mathrm{IntegerExponent}(2\,000)Out33

trailing zeros in base 10

live ↗
InIntegerExponent(1 230 000)\mathrm{IntegerExponent}(1\,230\,000)Out44
live ↗
InIntegerExponent(210×34,2)\mathrm{IntegerExponent}(2^{10}×3^4, 2)Out1010

1152 is 27⋅92^7\cdot 9, so the exponent of 2 is 7

live ↗
InIntegerExponent(1 152,2)\mathrm{IntegerExponent}(1\,152, 2)Out77

144=24⋅9144=2^4\cdot 9

live ↗
InIntegerExponent(144,2)\mathrm{IntegerExponent}(144, 2)Out44
Scope #

Composite base: 1728=26331728=2^6 3^3, so 636^3 divides it but 646^4 does not

live ↗
InIntegerExponent(1 728,6)\mathrm{IntegerExponent}(1\,728, 6)Out33

Negative integers

live ↗
InIntegerExponent(−1 000)\mathrm{IntegerExponent}(-1\,000)Out33

Threads over a list

live ↗
InIntegerExponent([10,100,1 000])\mathrm{IntegerExponent}(\bigl\lbrack10, 100, 1\,000\bigr\rbrack)Out[1,2,3]\bigl\lbrack1, 2, 3\bigr\rbrack

Gaussian integers: 8i=i⋅(−i)3(1+i)68i=i\cdot(-i)^3(1+i)^6

live ↗
InIntegerExponent(8i,1+i)\mathrm{IntegerExponent}(8i, 1+i)Out66
Applications #

The trailing zeros of 100!100!

live ↗
InIntegerExponent(100!)\mathrm{IntegerExponent}(100!)Out2424

The 2-adic valuation of each integer, the ruler sequence

live ↗
InIntegerExponent(1..50,2)\mathrm{IntegerExponent}(1..50, 2)Out[0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1]\bigl\lbrack0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1\bigr\rbrack
Properties #

Legendre's formula: ⌊100/7⌋+⌊100/49⌋=16\lfloor100/7\rfloor+\lfloor100/49\rfloor=16

live ↗
InIntegerExponent(100!,7)\mathrm{IntegerExponent}(100!, 7)Out1616

2524=4⋅6312524=4\cdot 631

live ↗
InIntegerExponent(2 524,2)\mathrm{IntegerExponent}(2\,524, 2)Out22
Possible issues #
live ↗
InIntegerExponent(0,5)\mathrm{IntegerExponent}(0, 5)Out∞∞

Base 1 has no well-defined pp-adic valuation, so the call stays unevaluated

live ↗
InIntegerExponent(10,1)\mathrm{IntegerExponent}(10, 1)OutIntegerExponent(10,1)\mathrm{IntegerExponent}(10, 1)
About
Examples19
Checked againstWolfram Language 18 agree1 differSymPy 9 agree3 error
CrosswalkWolfram LanguageSymPy

Implementation

mappedwolframpackages/oracle/src/mappings.ts
mappedsympypackages/oracle/src/mappings.ts

See also: AdicValuation, FactorInteger