Given **N** distinct objects, the task is to find the number of distinct arrangements of **N** objects if all clockwise arrangements are considered the same.

If A, B, and C are three distinct objects, then arrangements {A, B, C}, {C, A, B}, and {B, C, A} are considered the same as all the arrangements are clockwise to each other.

**Examples:**

Input:N = 3Output:2Explanation:

Permutation of 3 distinct objects can be represented as these 6 arrangements: {A, B, C}, {A, C, B}, {B, A, C}, {B, C, A}, {C, A, B} and {C, B, A}. But arrangement {A, B, C}, {C, A, B} and {B, C, A} are considered the same.

The arrangements {A, C, B}, {B, A, C} and {C, B, A} are also considered the same.

Hence, there are only 2 distinct arrangements.

Input:N = 2Output:1Explanation:

There can only 2 arrangements: {A, B} and {B, A}. Both these arrangements are same considering the clockwise arrangements.

Hence, only 1 distinct arrangement exist.

**Naive Approach:** The idea is to generate all the permutation of **N**** **distinct objects. Now, iterate all the arrangements and increment the counter if the current arrangement’s clockwise rotation is not present in previous arrangements. After checking all the arrangements, print the counter as the total distinct clockwise arrangements possible.

**Time Complexity:** O(N*N!)**Auxiliary Space:** O(N*N!)

**Efficient Approach:** The idea is to use the following observation:

Given a permutation {A

_{1}, A_{2}, …, A_{N}} of N distinct objects. Then, there can be N clockwise rotated arrangements denotes as follows:{A

_{1}, A_{2}, …, A_{N}}

{A_{N}, A_{1}, …, A_{N-1}}

{A_{N-1}, A_{N}, …, A_{N-2}}

{A_{N-2}, A_{N-1}, …, A_{N-3}}

and so on.Therefore, for each permutation of length

Nthere existN clockwisearrangements. Also, for N distinct objects, there areN!arrangements without considering the clockwise arrangements same.Hence, N*X = N!, where

N the clockwise arrangements of any permutation of length N.

X is the number of permutations considering clockwise arrangements the same.

N! is the total number of permutations.Using the above equation:

X = N! / N

X = (N – 1)!

Hence, the total number of distinct permutations considering clockwise arrangements the same is **(N – 1)!**. Therefore, the task is to print the value of factorial **(N – 1)**.

Below is the implementation of the above approach:

## C++

`// C++ program for the above approach` `#include <iostream>` `using` `namespace` `std;` `// Function to return the factorial` `// of given number` `unsigned ` `int` `factorial(unsigned ` `int` `n)` `{` ` ` `// Base case` ` ` `if` `(n == 0)` ` ` `return` `1;` ` ` `// Recursively find the factorial` ` ` `return` `n * factorial(n - 1);` `}` `// Driver Code` `int` `main()` `{` ` ` `// Given N objects` ` ` `int` `N = 4;` ` ` `// Function Call` ` ` `cout << factorial(N - 1);` ` ` `return` `0;` `}` |

*chevron_right*

*filter_none*

## Java

`// Java program for the above approach` `import` `java.io.*;` `class` `GFG{` ` ` `// Function to return the factorial` `// of given number` `static` `int` `factorial(` `int` `n)` `{` ` ` ` ` `// Base case` ` ` `if` `(n == ` `0` `)` ` ` `return` `1` `;` ` ` `// Recursively find the factorial` ` ` `return` `n * factorial(n - ` `1` `);` `}` `// Driver Code` `public` `static` `void` `main (String[] args)` `{` ` ` ` ` `// Given N objects` ` ` `int` `N = ` `4` `;` ` ` `// Function Call` ` ` `System.out.print(factorial(N - ` `1` `));` `}` `}` `// This code is contributed by math_lover` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program for the above approach` `# Function to return the factorial` `# of a given number` `def` `factorial(n):` ` ` `# Base Case` ` ` `if` `n ` `=` `=` `0` `:` ` ` `return` `1` ` ` ` ` `# Recursively find the factorial` ` ` `return` `n ` `*` `factorial(n` `-` `1` `)` `# Driver Code` `# Given N objects` `N ` `=` `4` `# Function Call` `print` `(factorial(N ` `-` `1` `))` |

*chevron_right*

*filter_none*

## C#

`// C# program for the ` `// above approach` `using` `System;` `class` `GFG{` ` ` `// Function to return ` `// the factorial` `// of given number` `static` `int` `factorial(` `int` `n)` `{ ` ` ` `// Base case` ` ` `if` `(n == 0)` ` ` `return` `1;` ` ` `// Recursively find the ` ` ` `// factorial` ` ` `return` `n * factorial(n - 1);` `}` `// Driver Code` `public` `static` `void` `Main(String[] args)` `{ ` ` ` `// Given N objects` ` ` `int` `N = 4;` ` ` `// Function Call` ` ` `Console.Write(factorial(N - 1));` `}` `}` `// This code is contributed by gauravrajput1` |

*chevron_right*

*filter_none*

**Output**

6

**Time Complexity:** O(N)**Auxiliary Space:** O(1)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Number of ways to arrange K different objects taking N objects at a time
- Calculate Stirling numbers which represents the number of ways to arrange r objects around n different circles
- Count clockwise array rotations required to maximize count of array elements present at indices same as their value
- Number of ways of distributing N identical objects in R distinct groups with no groups empty
- Number of ways of distributing N identical objects in R distinct groups
- Find ways to arrange K green balls among N balls such that exactly i moves is needed to collect all K green balls
- Number of ways to arrange a word such that all vowels occur together
- Count number of ways to arrange first N numbers
- Find the sum of the costs of all possible arrangements of the cells
- Ways to arrange Balls such that adjacent balls are of different types
- Number of ways to arrange a word such that no vowels occur together
- Number of ways to arrange 2*N persons on the two sides of a table with X and Y persons on opposite sides
- Number of ways to arrange N numbers which are in a range from 1 to K under given constraints.
- Minimum De-arrangements present in array of AP (Arithmetic Progression)
- Total number Of valid Home delivery arrangements
- Length of array pair formed where one contains all distinct elements and other all same elements
- Reaching a point using clockwise or anticlockwise movements
- Check if given permutation of 1 to N can be counted in clockwise or anticlockwise direction
- Arrange first N natural numbers such that absolute difference between all adjacent elements > 1
- Count ways to split N! into two distinct co-prime factors

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.