Skip to content
CalcGospel 微積分福音
返回

96 政大微積分 第 6 題

考題 / 轉學考微積分 / 政大 / 微積分

96學年度 · 96微積分 · 第 6 題

題目

Problem

6. Consider the following sequence of instructions.

  1. Set k=999k=999, i=1i=1, and p=0p=0.
  2. If k>ik>i, then go to step 3; otherwise go to step 5.
  3. Replace ii with 2i2i and replace pp with p+1p+1.
  4. Go to step 2.
  5. Print pp.

If these instructions are followed, what number will be printed at step 5?

(A) 11 (B) 22 (C) 1010 (D) 512512 (E) 999999

解答

解法一

思路

展開
  • 每執行一輪就把 ii 加倍,將停止條件改寫成對 2p2^p 的比較。

答題過程

展開

ii 從 11 開始,執行 pp 輪後 i=2pi=2^p。由於 29=512<999<1024=2102^9=512<999<1024=2^{10},第 1010 輪才使 k>ik>i 不成立。因此程式印出 1010,選 C\boxed{\text{C}}。