Skip to content
Exercise · Loops · lesson 6 of 8

Exercise: divisor count

Write a function int divisor_count(int n) that returns the number of divisors of n. The divisors are the numbers from 1 to n that divide n with no remainder.

  • divisor_count(12) → 6
  • divisor_count(13) → 2
  • divisor_count(1) → 1

Constraints: n is from 1 to 10000.

divisor_count.cpp — cpp
cpp · 4 lines
Ctrl+Enter run · Esc leave editor