Minimum Cuts to Divide a Circle

🏠 ⬅️ ➑️

A valid cut in a circle can be:

  • A cut that is represented by a straight line that touches two points on the edge of the circle and passes through its center, or
  • A cut that is represented by a straight line that touches one point on the edge of the circle and its center.

Some valid and invalid cuts are shown in the figures below.

Given the integer n, return the minimum number of cuts needed to divide a circle into n equal slices.

Example 1:

Input: n = 4 Output: 2 Explanation: The above figure shows how cutting the circle twice through the middle divides it into 4 equal slices.

Example 2:

Input: n = 3 Output: 3 Explanation: At least 3 cuts are needed to divide the circle into 3 equal slices. It can be shown that less than 3 cuts cannot result in 3 slices of equal size and shape. Also note that the first cut will not divide the circle into distinct parts.

Constraints:

  • 1 <= n <= 100

Note: This problem is from LeetCode.
βœ… Compiled
❌ Executed
❌ Correct
program main
    implicit none

    integer :: n

    print '(A)', 'Enter the value of n:'
    read *, n

    print '(I0)', minCuts(n)

contains

    function minCuts(n) result(cuts)
        implicit none
        integer, intent(in) :: n
        integer :: cuts

        if (n == 1) then
            cuts = 0
        else if (n == 2) then
            cuts = 1
        else
            cuts = 2
        end if
    end function minCuts
end program main
❌ Compiled
❌ Executed
❌ Correct
PROGRAM main
      IMPLICIT NONE

      INTEGER :: n, i, j, k, l, m, n_cuts
      REAL :: x1, y1, x2, y2, x3, y3, x4, y4

      READ(*,*) n

      ! Initialize the number of cuts to 0
      n_cuts = 0

      ! Check if n is valid
      IF (n < 1 .OR. n > 100) THEN
         WRITE(*,*) "Invalid input"
         STOP
      END IF

      ! Check if n is 1
      IF (n == 1) THEN
         WRITE(*,*) "0"
         STOP
      END IF

      ! Check if n is 2
      IF (n == 2) THEN
         WRITE(*,*) "1"
         STOP
      END IF

      ! Check if n is 3
      IF (n == 3) THEN
         WRITE(*,*) "2"
         STOP
      END IF

      ! Check if n is 4
      IF (n == 4) THEN
         WRITE(*,*) "3"
         STOP
      END IF

      ! Check if n is 5
      IF (n == 5) THEN
         WRITE(*,*) "4"
         STOP
      END IF

      ! Check if n is 6
      IF (n == 6) THEN
         WRITE(*,*) "5"
         STOP
      END IF

      ! Check if n is 7
      IF (n == 7) THEN
         WRITE(*,*) "6"
         STOP
      END IF

      ! Check if n is 8
      IF (n == 8) THEN
         WRITE(*,*) "7"
         STOP
      END IF

      ! Check if n is 9
      IF (n == 9) THEN
         WRITE(*,*) "8"
         STOP
      END IF

      ! Check if n is 10
      IF (n == 10) THEN
         WRITE(*,*) "9"
         STOP
      END IF

      ! Check if n is 11
      IF (n == 11) THEN
         WRITE(*,*) "10"
         STOP
      END IF

      ! Check if n is 12
      IF (n == 12) THEN
         WRITE(*,*) "11"
         STOP
      END IF

      ! Check if n is 13
      IF (n == 13) THEN
         WRITE(*,*) "12"
         STOP
      END IF

      ! Check if n is 14
      IF (n == 14) THEN
         WRITE(*,*) "13"
         STOP
      END IF

      ! Check if n is 15
      IF (n == 15) THEN
         WRITE(*,*) "14"
         STOP
      END IF

      ! Check if n is 16
      IF (n == 16) THEN
         WRITE(*,*) "15"
         STOP
      END IF

      ! Check if n is 17
      IF (n == 17) THEN
         WRITE(*,*) "16"
         STOP
      END IF

      ! Check if n is 18
      IF (n == 18) THEN
         WRITE(*,*) "17"
         STOP
      END IF

      ! Check if n is 19
      IF (n == 19) THEN
         WRITE(*,*) "18"
         STOP
      END IF

      ! Check if n is 20
      IF (n == 20) THEN
         WRITE(*,*) "19"
         STOP
      END IF

      ! Check if n is 21
      IF (n == 21) THEN
         WRITE(*,*) "20"
         STOP
      END IF

      ! Check if n is 22
      IF (n == 22) THEN
         W
🌐 Data from online sources
def min_cuts(n):
    if n % 2 == 0:
        return n // 2
    else:
        return n
If `n` is an even number, then each cut divides the circle into two equal slices, and thus the minimum number of cuts required is `n / 2`. If `n` is an odd number, then each cut divides the circle into one equal slice, and thus the minimum number of cuts required is `n`.
🌐 Data from online sources
int min_cuts(int n) {
    if (n % 2 == 0)
        return n / 2;
    else
        return n;
}
If `n` is an even number, then each cut divides the circle into two equal slices, and thus the minimum number of cuts required is `n / 2`. If `n` is an odd number, then each cut divides the circle into one equal slice, and thus the minimum number of cuts required is `n`.