본문 바로가기

공부하자/Codility

[Codility] Lesson12. ChocolatesByNumbers (C#)

문제: app.codility.com/programmers/lessons/12-euclidean_algorithm/chocolates_by_numbers/

 

ChocolatesByNumbers coding task - Learn to Code - Codility

There are N chocolates in a circle. Count the number of chocolates you will eat.

app.codility.com

 

 

 

 

            if (N == 1) return 1;
            int gcd = getGCD(N, M);

            return N / gcd;


        static int getGCD(int N, int M)
        {
            if (M == 0) return N;
            return getGCD(M, N % M);
        }