{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Proof\n\n1. Let $p$ be a [[prime number|0SN0MAEKYX]] and let $a$ be an integer with $p \\nmid a$. Let $R = \\{ 1, 2, \\dots, p - 1 \\}$.\n2. For $i \\in R$, we have $0 \u003c i \u003c p$, so $p$ does not [[divide|096PW7Q014]] $i$. Since also $p \\nmid a$, [[Euclid's lemma|051VYKA1EX]] gives $p \\nmid i a$.\n3. For $i \\in R$, let $r_i$ be the remainder of $i a$ on division by $p$, given by the [[division algorithm|0CHQKZFK5S]]. Then $0 \\le r_i \u003c p$ and $r_i \\equiv i a \\pmod p$.\n4. If $r_i = 0$, then $p$ divides $i a$, which contradicts step 2. So $r_i \\in R$.\n5. Let $i, j \\in R$ with $r_i = r_j$. Then $i a \\equiv j a \\pmod p$, so $p$ divides $(i - j) a$.\n6. Since $p \\nmid a$, Euclid's lemma gives $p \\mid i - j$. Since $\\abs{i - j} \u003c p$, this forces $i - j = 0$, so $i = j$.\n7. By steps 4 and 6, the numbers $r_1, \\dots, r_{p-1}$ are $p - 1$ distinct elements of $R$. Since $R$ has $p - 1$ elements, they are all the elements of $R$ in some order.\n8. Hence $r_1 r_2 \\cdots r_{p-1} = 1 \\cdot 2 \\cdots (p - 1) = (p - 1)!$.\n9. By step 3 and [[compatibility with multiplication|072D5G4SK6]], $\\prod_{i=1}^{p-1} (i a) \\equiv \\prod_{i=1}^{p-1} r_i \\pmod p$.\n10. The left side of step 9 is $a^{p-1} (p - 1)!$. With step 8, we get $a^{p-1} (p - 1)! \\equiv (p - 1)! \\pmod p$.\n11. So $p$ divides $(a^{p-1} - 1) (p - 1)!$.\n12. The prime $p$ does not divide $(p - 1)!$. Otherwise, Euclid's lemma applied to the factors $1, \\dots, p - 1$ in turn would give $p \\mid i$ for some $i \\in R$, against step 2.\n13. By steps 11 and 12 and Euclid's lemma, $p$ divides $a^{p-1} - 1$. Hence $a^{p-1} \\equiv 1 \\pmod p$.\n\n## Idea\n\nMultiplying the nonzero residues $1, \\dots, p - 1$ by $a$ only shuffles them. So the product of all of them is unchanged, except for the factor $a^{p-1}$ that comes out. Cancelling the product $(p - 1)!$, which $p$ does not divide, leaves $a^{p-1} \\equiv 1$.\n",
  "commit": "68a8c3dc73fd55004b2796431c607c30960d1a85",
  "front": {
    "kind": "proof",
    "methods": [
      "0NTF6DMVAP"
    ],
    "msc": [
      "11A07"
    ],
    "name": "Proof of Fermat's little theorem by rearrangement",
    "proves": "0M25PRN3WQ",
    "sources": [
      {
        "locator": "Proof as a particular case of Euler's theorem",
        "url": "https://en.wikipedia.org/wiki/Proofs_of_Fermat%27s_little_theorem"
      }
    ],
    "tag": "4W0R66PGGM",
    "uses": [
      "0SN0MAEKYX",
      "0TPW25CBN6",
      "096PW7Q014",
      "051VYKA1EX",
      "0CHQKZFK5S",
      "072D5G4SK6"
    ]
  },
  "kind": "proof",
  "link": "https://math2.tamnd.com/node/4W0R66PGGM/",
  "links": [
    {
      "field": "proves",
      "target": "0M25PRN3WQ"
    },
    {
      "field": "uses",
      "target": "0SN0MAEKYX"
    },
    {
      "field": "uses",
      "target": "0TPW25CBN6"
    },
    {
      "field": "uses",
      "target": "096PW7Q014"
    },
    {
      "field": "uses",
      "target": "051VYKA1EX"
    },
    {
      "field": "uses",
      "target": "0CHQKZFK5S"
    },
    {
      "field": "uses",
      "target": "072D5G4SK6"
    },
    {
      "field": "methods",
      "target": "0NTF6DMVAP"
    }
  ],
  "markdown": "https://math2.tamnd.com/node/4W0R66PGGM.md",
  "msc": [
    "11A07"
  ],
  "name": "Proof of Fermat's little theorem by rearrangement",
  "prov": null,
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/4W0/4W0R66PGGM.md",
  "status": null,
  "tag": "4W0R66PGGM",
  "uri": "m2://4W0R66PGGM",
  "url": "https://math2.tamnd.com/wiki/proof-of-fermats-little-theorem-by-rearrangement/",
  "writing": {
    "tag": "4W0R66PGGM",
    "kind": "proof",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      }
    ]
  }
}
