[알고리즘문제풀기] 피자 나눠 먹기 (2)

silver's avatar
Dec 13, 2025
[알고리즘문제풀기] 피자 나눠 먹기 (2)

문제

내가 작성한 정답

class Solution { public int solution(int n) { for(int i=1; i<=50; i++){ if((6*i)%n==0) return i; } return 0; } }

다른 사람들의 정답

class Solution { public int solution(int n) { int answer = 1; while(true){ if(6*answer%n==0) break; answer++; } return answer; } } class Solution { public int solution(int n) { return n / gcd(6, n); } int gcd(int m, int n) { return m % n == 0 ? n : gcd(n, m % n); } }
Share article

silver