Problem Statement
Trisha just finished her lesson on complex numbers. To test her knowledge, her professor gave her an assignment. Trisha should find the value of the following expression:

In the formula, α1, α2, . . . αn-1 are all distinct n-th roots of unity other than 1.
You are given the int n. Let X be the value of the above expression. If X is an integer, return X. Otherwise, return -1.
Definition
- Class:
- SolveForTrisha
- Method:
- findSolution
- Parameters:
- int
- Returns:
- int
- Method signature:
- int findSolution(int n)
- (be sure your method is public)
Notes
- You can read more about roots of unity here: https://en.wikipedia.org/wiki/Root_of_unity
- You can read more about complex numbers here: https://en.wikipedia.org/wiki/Complex_number
Constraints
- n will be between 2 and 109, inclusive.
Examples
2
Returns: 0
The only second root of unity other than 1 is -1. The formula is a product that consists of one term: 1 - (-1)2 = 0.3
Returns: 3
The third roots of unity are α0 = 1, α1 = cos(120) + i*sin(120), and α2 = cos(240) + i*sin(240), where all angles are in degrees. The expression (1 - α12) * (1 - α22) evaluates to exactly 3.