Smallest Even Multiple - Problem
Given a positive integer n, you need to find the smallest positive integer that is a multiple of both 2 and n.
In other words, find the Least Common Multiple (LCM) of 2 and n.
Example: If n = 5, the multiples of 5 are [5, 10, 15, 20, ...] and the multiples of 2 are [2, 4, 6, 8, 10, 12, ...]. The smallest number that appears in both sequences is 10.
This is a fundamental number theory problem that helps you understand the relationship between LCM and GCD.
Input & Output
example_1.py โ Basic Even Number
$
Input:
n = 6
โบ
Output:
6
๐ก Note:
Since 6 is already even, it's divisible by both 2 and 6. The LCM of 2 and 6 is 6.
example_2.py โ Basic Odd Number
$
Input:
n = 5
โบ
Output:
10
๐ก Note:
5 is odd, so we need the first multiple of 5 that's also even. That would be 5ร2 = 10.
example_3.py โ Edge Case Minimum
$
Input:
n = 1
โบ
Output:
2
๐ก Note:
1 is odd, so the smallest multiple of both 1 and 2 is 1ร2 = 2.
Constraints
- 1 โค n โค 150
- n is a positive integer
- The result will always fit in a 32-bit integer
Visualization
Tap to expand
Understanding the Visualization
1
Even Numbers
If n is even, it already contains factor 2, so LCM(2,n) = n
2
Odd Numbers
If n is odd, gcd(2,n) = 1, so LCM(2,n) = 2รn
3
Pattern
This creates a simple conditional: return n if even, 2n if odd
Key Takeaway
๐ฏ Key Insight: The parity (even/odd nature) of n directly determines the LCM with 2, making this an O(1) solution.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code