Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find the Number Below N Having the Maximum Number of Divisors

Basic Acceptance 87.33% Points 10.00

You are given a positive integer N. Your task is to return the smallest number in the range from 1 to N that has the greatest number of positive divisors. If multiple numbers share the maximum divisor count, return the smallest one.

Examples
Example 1

Input: N = 10
Output: 6
Explanation: The number 6 has four positive divisors: 1, 2, 3, and 6. No number from 1 to 10 has more than four divisors, and 6 is the smallest number with this maximum count.

Example 2

Input: N = 15
Output: 12
Explanation: The number 12 has six positive divisors: 1, 2, 3, 4, 6, and 12. This is the maximum divisor count in the range from 1 to 15.

Example 3

Input: N = 1
Output: 1
Explanation: The only candidate is 1, which has exactly one positive divisor.

Constraints
  • 1 = N = 105
Companies
Microsoft eBay Paytm
Topics
Data Structures Basics Basics
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions