
Prime factorization
Calculate prime factorization with clear inputs and assumptions.
Your inputs stay in your browser. Displayed results are rounded to a maximum of 12 significant digits.
Method and assumptions
Method version 1.0.0 · Updated
Calculate
Formula: Calculate prime factorization with clear inputs and assumptions.
Calculate prime factorization with clear inputs and assumptions.
- value
- Positive integer
Results are estimates where noted and depend on the entered assumptions.
Calculate with code
These short examples use the same inputs and core calculation as this tool. Adapt validation and formatting to your application.
JavaScript
function factors(n) { const out = []; for (let p = 2; p * p <= n; p++) while (n % p === 0) { out.push(p); n /= p; } if (n > 1) out.push(n); return out; }
console.log(factors(84)); // [2, 2, 3, 7]TypeScript
function factors(n: number): number[] { const out: number[] = []; for (let p = 2; p * p <= n; p++) while (n % p === 0) { out.push(p); n /= p; } if (n > 1) out.push(n); return out; }
console.log(factors(84)); // [2, 2, 3, 7]Python
def factors(n):
out, p = [], 2
while p * p <= n:
while n % p == 0: out.append(p); n //= p
p += 1
if n > 1: out.append(n)
return out
print(factors(84)) # [2, 2, 3, 7]Java
int n = 84;
for (int p = 2; p * p <= n; p++) while (n % p == 0) { System.out.print(p + " "); n /= p; }
if (n > 1) System.out.println(n); // 2 2 3 7C#
int n = 84;
for (int p = 2; p * p <= n; p++) while (n % p == 0) { Console.Write($"{p} "); n /= p; }
if (n > 1) Console.WriteLine(n); // 2 2 3 7