{
  "id": "factor",
  "version": "df1627f5805c",
  "status": "published",
  "name": "Factor Calculator",
  "question": "What are the factors of a number?",
  "summary": "Lists every factor of a whole number, its factor pairs, and its prime factorization, and says whether it is prime.",
  "category": "math",
  "subcategory": "arithmetic",
  "url": "https://www.acalculator.org/math/factor-calculator",
  "markdown": "https://www.acalculator.org/math/factor-calculator.md",
  "kind": "function",
  "method": "Trial division: divide n by 2, 3, 5, 7, … up to √n for the prime factorization, then list every product of the prime powers.",
  "assumptions": [
    "n is a whole number from 1 to 1,000,000,000,000 (10¹²).",
    "Only positive factors are listed; each negative factor −f also divides n.",
    "1 is not a prime number."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "n": {
        "title": "Whole number",
        "description": "The whole number to factor, from 1 to 1,000,000,000,000.",
        "type": "integer",
        "minimum": 1,
        "maximum": 1000000000000
      }
    }
  },
  "outputs": {
    "factors": {
      "label": "Factors",
      "description": "Every whole number that divides n with no remainder, smallest first.",
      "format": "text"
    },
    "count": {
      "label": "Number of factors",
      "description": "How many factors n has.",
      "format": "integer"
    },
    "pairs": {
      "label": "Factor pairs",
      "description": "Pairs of factors that multiply to n, such as 3 × 20 for 60.",
      "format": "text"
    },
    "primeFactorization": {
      "label": "Prime factorization",
      "description": "n written as a product of primes, with powers: 60 = 2² × 3 × 5.",
      "format": "text"
    },
    "prime": {
      "label": "Prime number?",
      "description": "Yes when n has exactly two factors, 1 and itself.",
      "format": "boolean"
    },
    "sum": {
      "label": "Sum of the factors",
      "description": "All the factors added together, n included.",
      "format": "integer"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "n": 60
    },
    "outputs": {
      "factors": "1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60",
      "count": 12,
      "pairs": "1 × 60, 2 × 30, 3 × 20, 4 × 15, 5 × 12, 6 × 10",
      "primeFactorization": "2² × 3 × 5",
      "prime": false,
      "sum": 168
    },
    "text": "The factors of 60 (12 in all) are 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60."
  },
  "examples": [
    {
      "given": {
        "n": 60
      },
      "expect": {
        "factors": "1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60",
        "count": 12,
        "pairs": "1 × 60, 2 × 30, 3 × 20, 4 × 15, 5 × 12, 6 × 10",
        "primeFactorization": "2² × 3 × 5",
        "prime": false,
        "sum": 168
      },
      "source": "hand calculation in content.mdx: 60 = 2² × 3 × 5, (2 + 1)(1 + 1)(1 + 1) = 12 factors"
    },
    {
      "given": {
        "n": 97
      },
      "expect": {
        "factors": "1, 97",
        "count": 2,
        "pairs": "1 × 97",
        "primeFactorization": "97",
        "prime": true,
        "sum": 98
      },
      "source": "hand calculation in content.mdx: no prime up to √97 ≈ 9.8 (2, 3, 5, 7) divides 97"
    },
    {
      "given": {
        "n": 36
      },
      "expect": {
        "factors": "1, 2, 3, 4, 6, 9, 12, 18, 36",
        "count": 9,
        "pairs": "1 × 36, 2 × 18, 3 × 12, 4 × 9, 6 × 6",
        "primeFactorization": "2² × 3²"
      },
      "source": "hand calculation in content.mdx: 36 = 2² × 3², a perfect square with an odd number of factors"
    },
    {
      "given": {
        "n": 1
      },
      "expect": {
        "factors": "1",
        "count": 1,
        "pairs": "1 × 1",
        "primeFactorization": "1",
        "prime": false,
        "sum": 1
      },
      "source": "hand calculation in content.mdx: 1 has one factor and is not prime"
    },
    {
      "given": {
        "n": 1000000000000
      },
      "expect": {
        "count": 169,
        "primeFactorization": "2¹² × 5¹²",
        "sum": 2499694822171
      },
      "source": "hand calculation in content.mdx: 10¹² = 2¹² × 5¹², (12 + 1)(12 + 1) = 169 factors; Python 3: (2**13 - 1) * (5**13 - 1) // 4 = 2499694822171"
    },
    {
      "given": {
        "n": 999999999989
      },
      "expect": {
        "count": 2,
        "prime": true
      },
      "source": "Python 3 trial division: no divisor of 999,999,999,989 from 2 to 999,999 (the largest prime below 10¹²)"
    }
  ],
  "sources": [
    "OpenStax, Prealgebra 2e, section 2.4 Find Multiples and Factors: https://openstax.org/books/prealgebra-2e/pages/2-4-find-multiples-and-factors",
    "OpenStax, Prealgebra 2e, section 2.5 Prime Factorization and the Least Common Multiple: https://openstax.org/books/prealgebra-2e/pages/2-5-prime-factorization-and-the-least-common-multiple"
  ],
  "related": [
    "gcf",
    "lcm",
    "square-root"
  ],
  "changelog": []
}
