{
  "familyId": "math.gcd",
  "version": 1,
  "status": "draft",
  "name": "兩個正整數最大公因數",
  "scope": "恰好兩個已確認、1至20位的十進位正整數，求其最大公因數。",
  "exclusions": [
    "零與負數",
    "分數或小數記法",
    "三個以上數的共同因數",
    "數值來源或OCR尚未確認",
    "超過20位整數另立支援範圍"
  ],
  "parameterSchema": {
    "type": "object",
    "required": [
      "a",
      "b",
      "confirmed"
    ],
    "properties": {
      "a": {
        "type": "string",
        "pattern": "^[1-9][0-9]{0,19}$"
      },
      "b": {
        "type": "string",
        "pattern": "^[1-9][0-9]{0,19}$"
      },
      "confirmed": {
        "const": true
      },
      "extraNumbers": {
        "type": "array",
        "maxItems": 0
      }
    },
    "additionalProperties": false,
    "notes": "先確認缺失或未確認條件，再檢查只含兩個正整數。0、負數、分數及小數字面記法均不屬此子型；使用精確 BigInt，不能轉成浮點數。"
  },
  "methods": [
    {
      "methodId": "gcd.enumeration",
      "version": 1,
      "applicability": "教學預設；a、b皆≤200，已理解整除與因數；不能用此法硬列舉大數。",
      "steps": [
        {
          "id": "s1",
          "stage": 0,
          "title": "確認兩個數",
          "instruction": "確認 a、b 是題目要求的兩個正整數。",
          "hint": "因數會整除原數。",
          "check": "原始數值、題目目標、confirmed 與參數一致。"
        },
        {
          "id": "s2",
          "stage": 1,
          "title": "找出各自因數",
          "instruction": "由1至各數逐一驗整除，產生各自完整升序因數列表。",
          "hint": "沒有餘數才列入。",
          "check": "列表每值為正整數且整除對應原數，完整性由配對因數獨立核對。"
        },
        {
          "id": "s3",
          "stage": 2,
          "title": "標出共同因數",
          "instruction": "取兩份因數列表的交集，依升序標示共同值。",
          "hint": "兩邊都有的數才是共同因數。",
          "check": "交集與原列表完全一致，不遺漏1。"
        },
        {
          "id": "s4",
          "stage": 3,
          "title": "選最大並確認",
          "instruction": "取共同因數列表最大值 d，請學生回到本步確認。",
          "hint": "不是任選一個共同因數。",
          "check": "d整除a與b，且獨立輾轉相除的結果等於d。"
        }
      ],
      "validatorRefs": [
        "input.confirmed-conditions",
        "input.positive-integer-pair",
        "gcd.divisibility-maximality"
      ],
      "diagramRefs": [
        "math.gcd.factor-list"
      ]
    },
    {
      "methodId": "gcd.euclidean",
      "version": 1,
      "applicability": "非列舉範圍，且已確認除法餘數概念。未確認概念先補一個餘數小例，不直接丟演算法；計算可獨立使用精確演算法。",
      "steps": [
        {
          "id": "s1",
          "stage": 0,
          "title": "確認數值與餘數觀念",
          "instruction": "固定較大數A及較小數B，均正整數。",
          "hint": "交換輸入順序不會改變最大公因數。",
          "check": "A=max(a,b)，B=min(a,b)。"
        },
        {
          "id": "s2",
          "stage": 1,
          "title": "做一次整數除法",
          "instruction": "以A=qB+r寫出商和餘數。",
          "hint": "餘數介於0到B−1。",
          "check": "A=qB+r 且0≤r<B，皆用精確整數。"
        },
        {
          "id": "s3",
          "stage": 2,
          "title": "保留共同因數關係",
          "instruction": "若r非零，換成B與r，重複至餘數0。",
          "hint": "同時整除A及B的數，也會整除A−qB。",
          "check": "每輪候選共同因數集合不變，除數嚴格下降。"
        },
        {
          "id": "s4",
          "stage": 3,
          "title": "最後非零除數",
          "instruction": "餘數0時最後除數為答案d。",
          "hint": "可用a÷d、b÷d檢查。",
          "check": "兩原數皆被d整除，trace所有等式有效，最後餘數0。"
        }
      ],
      "validatorRefs": [
        "input.confirmed-conditions",
        "input.positive-integer-pair",
        "gcd.divisibility-maximality",
        "gcd.euclidean-trace"
      ],
      "diagramRefs": [
        "math.gcd.euclidean-table"
      ]
    }
  ],
  "svgTemplateSpecs": [
    {
      "templateId": "math.gcd.factor-list",
      "version": 1,
      "parameters": [
        "a",
        "b",
        "factorsA",
        "factorsB",
        "commonFactors",
        "answer"
      ],
      "domainGuards": [
        "a,b≤200",
        "所有列表由精確整除產生且完整",
        "answer=max(commonFactors)",
        "每列最多50項，超出改表格而非刪值"
      ],
      "primitives": [
        "兩個標題及可換行升序因數文字格",
        "兩列共同數字同色框線",
        "answer格加最深色外框",
        "可見圖例：共同因數／最大公因數"
      ],
      "revealSequence": [
        "stage0只顯示a、b",
        "stage1顯示兩列全部因數",
        "stage2只標共同因數",
        "stage3框答案並顯示a÷d、b÷d皆整數"
      ],
      "fallback": "大數改 math.gcd.euclidean-table；不列部分因數冒充完整列表。SVG文字由受控參數填入，無腳本或外連。"
    },
    {
      "templateId": "math.gcd.euclidean-table",
      "version": 1,
      "parameters": [
        "a",
        "b",
        "divisionTrace",
        "answer"
      ],
      "domainGuards": [
        "每輪A=qB+r與0≤r<B",
        "trace末餘數0",
        "answer=最後非零除數"
      ],
      "primitives": [
        "分頁除法等式表",
        "每輪A、B、r相同色對應",
        "結尾答案及整除檢查"
      ],
      "revealSequence": [
        "確認原數",
        "顯示首輪",
        "逐輪新增可重播，預設每頁6輪",
        "框出最後非零除數"
      ],
      "fallback": "大整數換行、分頁，保留全部精確位數；不因版面縮短為近似值。"
    }
  ],
  "review": {
    "humanTeacherReviewed": false,
    "machineReview": "pending-mainline-validation",
    "promotionRule": "離線草稿案例通過不等於 approved，不接學生評分。"
  }
}
