본문 바로가기
C++

[프로그래머스] 피자 나눠 먹기(2)

by 띰쥬 2025. 9. 2.
728x90
반응형
SMALL

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int gcd(int a,int b) // a > b
{
    if(b==0)
        return a;
    else
        return gcd(b, a % b);
}

int lcm(int a,int b)
{
    return a*b/gcd(a,b);
}

int solution(int n) {
    
    //n과 6의 최소 공배수를 구하기
    return lcm(n,6)/6;
}

728x90
반응형
LIST

댓글