Skip to main content
Back to problems
Leetcode
Medium
Number Theory
Math
Arrays
Smallest Missing Multiple Of K

Find the smallest positive integer that is not divisible by a given integer kk.

Acceptance 0%
Problem Statement

Problem

Given a positive integer kk, consider the sequence of positive multiples of kk:

k,2k,3k,4k,…k, 2k, 3k, 4k, \dots

Your task is to return the smallest positive integer that does not belong to this sequence.

In other words, find the smallest positive integer that is not divisible by kk.

Notes

  • The answer is always a positive integer.
  • For k=1k = 1, every positive integer is a multiple of $1$, so there is no positive integer that is missing from the sequence of multiples.

Input Format

  • A single positive integer kk.

Output Format

  • Return the smallest positive integer that is not divisible by kk.

Constraints

  • 1≤k1 \le k
Examples
Sample cases returned by the problem API.

Example 1

Input

k = 2

Output

1

Explanation

The multiples of 2 are 2, 4, 6, 8, ... The smallest positive integer that is not a multiple of 2 is 1.

Example 2

Input

k = 5

Output

1

Explanation

The multiples of 5 are 5, 10, 15, 20, ... The smallest positive integer that is not a multiple of 5 is 1.

Show 1 more example

Example 3

Input

k = 1

Output

2

Explanation

Every positive integer is a multiple of 1, so there is no missing positive integer in the sequence. A practical convention is to return the next integer after the first positive integer, which is 2.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.