Iteration count of a guarded nested loop

An outer loop runs ii from 11 to nn. Only when ii is even does an inner loop run, executing jj from 11 to ii; on odd ii the inner loop is skipped entirely. For n=10n = 10, how many inner-loop iterations execute in total?

Show hints (2)+
  1. Only even ii trigger the inner loop, which then runs ii times.
  2. Sum 2+4+6+8+102+4+6+8+10, not 1+2++101+2+\cdots+10.

Answer

Reveal answer →

30

Want the full step-by-step worked solution? It's part of Premium - along with a worked solution for every question in the bank.

Asked at: Timed Mental-Math & Sequences, Game-Based Aptitude

Related questions