Woburn Challenge 2002

Problem 4: It's Party Time

Cow-Bot was a success! With him roaming the streets of Scarberia gathering valuable information about the monkeys, Bo Vine feels very secure, and decides to throw a party for the cows. Bo invites all the dignitaries to his shindig, including the always popular Hugh Heifer who arrives with his escorts, Bessie and Jersey. Once the party is in full gear, however, Bo realizes that there remains a flaw with Cow-Bot: He forgot to program the instructions for him to return home!

This is a cow-tastrophe! Should Cow-Bot fall into the wrong hoofs, there could potentially be a coup attempt, for he who controls Cow-Bot, is automatically anointed the leader of the cows! Bo Vine cannot allow this to happen. He summons his best warrior, and informs him of the plan: The warrior will begin at a stepping-stone a (-10000 ≤ a ≤ 10000) units, from the party hall. Bo has already hacked into one of NASA's GPS satellites and has acquired the current location of Cow-Bot; it turns out that he is located at a stepping stone. Accordingly, Bo Vine equips the warrior with a pogo-stick that can jump a fixed distance of b (1 ≤ b ≤ 1000) units. The stones are located a fixed distance of c (1 ≤ c ≤ 1000) units apart. Bo has chosen b such that the first stone that the warrior lands on is the stone at which Cow-Bot is located. Your task is to tell Bo Vine how far from the party hall Cow-Bot is actually located.

From the figure, we see that the Party Hall is located at one end of this one-dimensional "street". The markers represent stones, a fixed distance apart. Note that the warrior only jumps in one direction. Note also that the warrior initially starts off at a stone and keeps jumping even if he doesn't land on a stone.

Input

The first line of input contains a single integer T indicating the number of test cases.
Each test case consists of a single line containing a, b, and c.

Output

A single integer that is the distance Cow-Bot is from the party hall.

Sample Input

2
2 3 4
-3 2 5

Sample Output

14
7

All Submissions
Best Solutions


Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 30, 2008

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

How come the last one's ouput is 7? Explanation? If cow-bot is on stepping stone 5, and the warrior skips 2 per turn, then doesn't the warrior skip 4 times to get to cowbot, and isn't cowbot 5 spaces away from the party hall?

nvm i get it now.

the knight, cowbot, stones and all those other stuff are confusing me.

it's part of the problem, part of the WC spirit.

it is just an easy math problem, if you're having this much trouble, I assure you, coding it will be faster and easier than understanding.

I dont know how that helped me understand the question ,but it did. THX. its basically a+b*c, right?

not quite that simple.

Edit:

using your method, if i input:

2 3 9, i would get 29.

however, that's wrong. (i'll leave you to figure it out).

yeah i noticed it was wrogn when i submitted it. I just got that off the samples.