반응형
인트로 문제 절반 풀었다.
Consider integer numbers from 0 to n - 1 written down along the circle in such a way that the distance between any two neighbouring numbers is equal (note that 0 and n - 1 are neighbouring, too). Given n and firstNumber, find the number which is written in the radially opposite position to firstNumber. Example For n = 10 and firstNumber = 2, the output should be circleOfNumbers(n, firstNumber) = 7. |
code>>
int circleOfNumbers(int n, int firstNumber) {
return (n / 2 + firstNumber) % n;
}
반응형
'알고리즘 > codefights' 카테고리의 다른 글
32>absoluteValuesSumMinimization (0) | 2017.07.08 |
---|---|
31>depositProfit (0) | 2017.07.06 |
29>chessBoardCellColor (0) | 2017.07.06 |
28>alphabeticShift (0) | 2017.07.06 |
27>variableName (0) | 2017.07.06 |