Algorithm/LeetCode

2413. Smallest Even Multiple

https://leetcode.com/problems/smallest-even-multiple/

 

Smallest Even Multiple - LeetCode

Can you solve this real interview question? Smallest Even Multiple - Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.   Example 1: Input: n = 5 Output: 10 Explanation: The smallest multiple of both 5 and

leetcode.com

 

Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.

 

gcd / lcm 문제

class Solution {
    public int smallestEvenMultiple(int n) {
        return (2 * n) / gcd(2, n);
    }
    public int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
}