IPA FE Subject B 2025 Question 2

A question IPA Japan published in 令和7年度 基本情報技術者試験 科目B 公開問題 問2, translated into English. ITPEC is based on the same exams.

From the answer group below, select the correct answer to be inserted into blank in the program.

The function change receives an integer greater than 10 as the argument n, and returns the total number of combinations of 1-yen coins, 5-yen coins, and 10-yen coins that make exactly n yen.
For example, the combinations that make 12 yen are counted as follows. When no 10-yen coins are used, exactly 12 yen must be made with 1-yen coins and 5-yen coins only. Since the number of 5-yen coins that can be used is 0 or more and (the quotient of 12 ÷ 5) or less, there are (the quotient of 12 ÷ 5) + 1 = 3 such combinations. Similarly, when one 10-yen coin is used, exactly 2 yen must be made with 1-yen coins and 5-yen coins only, and there is (the quotient of 2 ÷ 5) + 1 = 1 such combination. There are no combinations that use two or more 10-yen coins. Therefore, there are 3 + 1 = 4 combinations that make exactly 12 yen with 1-yen coins, 5-yen coins, and 10-yen coins.

[Program]
○ integer: change(integer: n)
integer: count ← 0
integer: rest ← n
while (blank)
count ← count + (the quotient of rest ÷ 5) + 1
rest ← rest - 10
endwhile
return count

Answer group

Explanation

rest ≥ 0 — each pass of the loop counts the combinations that use one more 10-yen coin, and the pass where rest is exactly 0 (the amount paid in 10-yen coins alone) must be counted too.

Pass k (k = 0, 1, 2, …) handles k 10-yen coins: rest = n − 10k yen is left for 1-yen and 5-yen coins. That amount can use 0 up to (the quotient of rest ÷ 5) 5-yen coins, the remainder in 1-yen coins, so it adds (the quotient of rest ÷ 5) + 1 combinations. This holds for every rest of 0 or more: 1 to 4 yen is one combination (1-yen coins only), and 0 yen is one combination (nothing more to add). A negative rest means too many 10-yen coins, so the loop runs while rest ≥ 0.

npasses (rest: combinations)count
1212: 3, 2: 14
2020: 5, 10: 3, 0: 19

The first row is the question's own example; in the second, the pass at rest = 0 is the combination of two 10-yen coins.

Answer (a)

Why not others:

  • •(d) rest > 0 — skips the pass at rest = 0, so whenever n is a multiple of 10 the combination of 10-yen coins alone is lost: change(20) returns 8
  • •(b) rest ≥ 5, (c) rest ≥ 10, (e) rest > 5 and (f) rest > 10 — also skip a last rest below the threshold; for 12 yen all four drop the pass at rest = 2 (one 10-yen coin and two 1-yen coins) and return 3 instead of 4

Key rule: When a loop takes away one unit per pass, its condition must still admit the smallest valid remainder (here 0); check the boundary cases, such as an amount that is an exact multiple of 10.

Math & Numbers · AI-written, may contain errors

This question comes from the past questions IPA Japan publishes, translated into English by ITPEC Practice. ITPEC Practice is an independent study tool and is not affiliated with IPA or ITPEC. See the original paper (PDF) or Report an issue.