Algorithm/프로그래머스

[알고리즘] 피자 나눠 먹기 (2) Java

rw- 2023. 8. 2. 21:50
728x90

 

class Solution {
    public int solution(int n) {
        return lcm(n, 6) / 6;
    }
    
    static int gdc(int a, int b) {
        if (a < b) {
          int temp = a;
          a = b;
          b = temp;
        }
        while (b != 0) {
          int r = a % b;
          a = b;
          b = r;
        }
        return a;
      }

      static int lcm(int a, int b) {
        return a * b / gdc(a, b);
      }
}
728x90
반응형