Find number formed by K times alternatively reducing X and adding Y to 0 | Function to find the value obtained after alternatively reducing X and adding Y to 0 total K number of times ; Stores the final result after adding only Y to 0 ; Stores the final number after reducing only X from 0 ; Return the result obtained ; Driver Code
def positionAfterKJumps ( X , Y , K ) : NEW_LINE INDENT addY = Y * ( K // 2 ) NEW_LINE reduceX = - 1 * X * ( K // 2 + K % 2 ) NEW_LINE return addY + reduceX NEW_LINE DEDENT X = 2 NEW_LINE Y = 5 NEW_LINE K = 3 NEW_LINE print ( positionAfterKJumps ( X , Y , K ) ) NEW_LINE