In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of November 22nd
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #06 exercise sheet]


In this problem you should submit a function as described. Inside the function do not print anything that was not asked!

The name of the .py source file you submit to Mooshak should NOT start with a digit (you will get an error if you submit it like that).

[IP059] Cinnamon Jumping Game

Raj Koothrappali is spending his Saturday afternoon playing with his Yorkshire Terrier, Cinnamon.

To entertain her (and procrastinate from talking to actual people), Raj has designed a game: Cinnamon jumps forward and backward in a specific pattern! Here’s how it works:

Raj wants to calculate where Cinnamon ends up after all k jumps so he can predict where to put her treat!

Help him by implementing a function that computes Cinnamon’s final position.

The Problem

Write a function jump(k, a, b) that receives the number of jumps k and the integer jump sizes a and b, returning the final position of Cinnamon as described before.

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

1 ≤ k, a, b ≤ 109       Number of jumps and jump sizes

NOTE: the limits are high and you must have an efficient solution.
If your code simply simulates all jumps, iterating k times, it will result in a Time Limit Exceeded.


Example Function Calls Example Output
print(jump(3, 5, 2))
print(jump(4, 10, 3))
print(jump(5, 1, 10))
8
14
-17

Explanation of the example


Introduction to Programming (CC1024)
DCC/FCUP - University of Porto