{
  "schemaVersion": 1,
  "slug": "prime-factorization-calculator",
  "category": "math",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "a3cd28e2ce63b0c618631be92284975ee6ad238a7432068c92e6b16465204cfb",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/prime-factorization-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "n = Π p_i^a_i; τ(n) = Π(a_i + 1); σ(n) = Π Σ_{j=0}^{a_i} p_i^j",
    "vars": [
      [
        "n",
        "Integer ≥ 2"
      ],
      [
        "p_i",
        "Distinct prime factors"
      ],
      [
        "a_i",
        "Exponent of p_i"
      ],
      [
        "τ",
        "Divisor count"
      ],
      [
        "σ",
        "Sum of divisors"
      ]
    ],
    "note": "Uses trial division for integers from 2 to 1,000,000,000,000, testing 2 then odd divisors up to the square root of the remaining value. Larger factors may take longer to find."
  },
  "externalEvidence": {
    "reviewedAt": "2026-09-24",
    "sources": [
      {
        "name": "Wolfram MathWorld — Prime Factorization",
        "url": "https://mathworld.wolfram.com/PrimeFactorization.html"
      }
    ]
  },
  "contract": {
    "compute": "const n=Number(number);const bad=()=>({factorisation:null,primeFactorCount:null,distinctPrimes:null,divisorCount:null,divisorSum:null,expandedFactors:null,factorCheck:null,__error:'inputError'});\nif(!Number.isSafeInteger(n)||n<2||n>1000000000000)return bad();\nconst parts=[],steps=[],counts={};let m=n;\nfor(let p=2;p*p<=m;p+=(p===2?1:2)){while(m%p===0){steps.push({dividend:m,divisor:p,quotient:m/p});parts.push(p);counts[p]=(counts[p]||0)+1;m/=p;}}\nif(m>1){steps.push({dividend:m,divisor:m,quotient:1});parts.push(m);counts[m]=(counts[m]||0)+1;}\nconst keys=Object.keys(counts).map(Number).sort((a,b)=>a-b);\nlet divisors=[1];for(const p of keys){const previous=divisors.slice();let power=1;for(let i=1;i<=counts[p];i++){power*=p;for(const d of previous)divisors.push(d*power);}}\ndivisors.sort((a,b)=>a-b);\nreturn{factorisation:keys.map(p=>counts[p]>1?p+'^'+counts[p]:String(p)).join(' × '),expandedFactors:parts.join(' × '),factorCheck:parts.join(' × ')+' = '+n,primeFactorCount:parts.length,distinctPrimes:keys.length,divisorCount:divisors.length,divisorSum:divisors.reduce((a,b)=>a+b,0),__steps:steps,__divisors:divisors};",
    "inputs": [
      {
        "name": "number",
        "type": "number",
        "default": 360,
        "min": 2,
        "max": 1000000000000,
        "step": 1,
        "requiredValue": true,
        "strictRange": true
      }
    ],
    "outputs": [
      {
        "name": "factorisation",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "expandedFactors",
        "type": "text",
        "unit": ""
      },
      {
        "name": "primeFactorCount",
        "precision": 0,
        "unit": "",
        "trimTrailingZeros": true
      },
      {
        "name": "distinctPrimes",
        "precision": 0,
        "unit": "",
        "trimTrailingZeros": true
      },
      {
        "name": "divisorCount",
        "precision": 0,
        "unit": "",
        "trimTrailingZeros": true
      },
      {
        "name": "divisorSum",
        "precision": 0,
        "unit": "",
        "trimTrailingZeros": true
      },
      {
        "name": "factorCheck",
        "type": "text",
        "unit": ""
      }
    ],
    "interpret": null
  }
}
