Problem 165432 · hard · Phase 01 Prerequisites & Setup

Stickers on the Locker Row

functions · divisibility · counting · floor division

A school corridor has lockers numbered lo, lo + 1, ..., hi. On sticker day, m volunteers walk down the corridor one after another. Volunteer number k (for k = 1, 2, ..., m) puts one sticker on every locker in the corridor whose number is a multiple of k.

Write stickers(lo, hi, m) that returns the total number of stickers placed on the lockers numbered lo to hi (both included).

Examples

Input:  lo = 1, hi = 6, m = 6
Output: 14
Explanation: lockers 1..6 get 1, 2, 2, 3, 2, 4 stickers.

Input:  lo = 4, hi = 9, m = 3
Output: 11
Explanation: volunteer 1 marks 6 lockers, volunteer 2 marks 4, 6, 8,
volunteer 3 marks 6 and 9: 6 + 3 + 2 = 11.

Input:  lo = 10, hi = 10, m = 100
Output: 4

Constraints

  • 1 <= lo <= hi <= 10**12
  • 1 <= m <= 10**6

Goals

  • Count multiples of k in a range with floor division
  • Swap the order of a double count to avoid a slow loop
  • Write a small helper and reuse it
Starting Python…