Skip to content

平成21年度 春期 ITパスポート試験 問72

This question's explanation and your answers so far.

問72
頻出度★★☆

図1のように二つの正の数値 A1, A2 を読み取り, 二つの数値 B1, B2 を出力するボックスがある。B1 には A2 と同じ数値を出力し, B2 には A1 を A2 で割った余りを出力する。図2のようにこのボックスを2個つないだ場合, A1=15, A2=6 のとき後方のボックスの B1 に出力される数値は幾らか。 図1: 入力 A1, A2 → 「A2→B1」「A1/A2の余り→B2」→ 出力 B1, B2。 図2: 入力 15, 6 → ボックス1 → ボックス2 → 出力 B1, B2。

出典 平成21年度 春期 ITパスポート試験 問72
解説

問 72

  • Incorrectア

    0 is the value that appears at B2 of the rear box. The rear box receives A1=6 and A2=3, so B2 = the remainder of 6÷3 = 0. However, the question asks about B1 of the rear box, so this mixes up the two outputs.

  • イ

    正解 The correct answer is イ (3). Figure 1 defines only two rules for the box: “B1 outputs the same value as A2” and “B2 outputs the remainder of A1 divided by A2”. In Figure 2, 15 and 6 enter A1 and A2 of the front box, the front box's B1 connects to the rear box's A1, and the front box's B2 connects to the rear box's A2. Following this in order, the front box outputs B1=A2=6 and B2 = the remainder of 15÷6 = 3. The rear box therefore receives A1=6 and A2=3, and its B1 is, by the rule, the same value as A2, so it is 3 (incidentally, the rear box's B2 is the remainder of 6÷3 = 0). For this type of question, rather than memorizing the rules in the figure, it is safest to write the values out mechanically stage by stage, like a table for stage 1 and stage 2.

  • Incorrectウ

    6 is the value that appears at B1 of the front box (the initial A2 passed straight through), which is the value fed into A1 of the rear box. It is the answer you get by stopping at the first stage, not B1 of the rear box.

  • Incorrectエ

    15 is simply the A1 given at the start. The box's rule is to output A2 at B1, so the value of A1 never appears at B1 as it is; 15 is used only inside the front box to obtain “the remainder when divided by 6” and then disappears.

ここがポイント
  • For questions about processing boxes whose input/output rules are given in a figure, apply the rules straightforwardly and write out the values stage by stage. Here you can solve it just by applying the two rules B1=A2 (pass A2 straight on to the next stage) and B2 = the remainder of A1÷A2, in the order of stage 1 then stage 2.
  • Connecting these boxes in series is exactly the Euclidean algorithm (the procedure for finding the greatest common divisor), which keeps replacing two numbers as (A1, A2) → (A2, the remainder of A1÷A2). The divisor at the point where the remainder becomes 0 is the greatest common divisor, and indeed the greatest common divisor of 15 and 6 is 3.
用語

Your answers