Problem 169850 · easy · Phase 01 Prerequisites & Setup

Years Until the Town Reaches Its Target

loops · while · simulation · percent

A town has pop people. Every year it grows by percent percent, rounded down to whole people (the increase is pop * percent // 100). Write years_to_reach(pop, percent, target) that returns how many full years pass before the population is at least target. If it is already at least target, return 0.

Examples

Input:  pop = 1000, percent = 10, target = 1300
Output: 3
Explanation: 1000 -> 1100 -> 1210 -> 1331

Input:  pop = 500, percent = 5, target = 500
Output: 0

Constraints

  • 100 <= pop <= 10**6
  • 1 <= percent <= 100
  • 0 <= target <= 10**9

Goals

  • Loop until a threshold is reached rather than a fixed number of times
  • Apply a percentage increase step by step
Starting Python…