Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write code in python to solve the problem Input Format Each test contains several lines: Line 1: Four integers: x, a, b, m Line 2:

Write code in python to solve the problem

Input Format

Each test contains several lines:

Line 1: Four integers: x, a, b, m

Line 2: A single integer, q, indicating the number of queries

Each of the subsequent q lines contains a single integer denoting a value of n.

Output Format

For each value of n, output on a separate line, a single integer indicating the final position of the ball after n kicks.

Sample Input

1 2 3 10

1

2

Sample Output

1

Explanation

The wheel is marked with 10 positions (numbered clockwise from 0 to 9). The ball starts in position 1, and we want to know where it ends up after 2 kicks. On the first kick, it advances (clockwise) 2 positions (because a=2) once (because its current position at the time of the kick was 1) and then finally by 3 positions (because b=3) to end up at position 1+2+3=6. On the second kick, it advances 2 positions 6 times (i.e. from position 6 to positions 8, 0, 2, 4, 6, 8) and then 3 more positions to finally stop at position 1.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions

Question

Ability to work comfortably in a team environment

Answered: 1 week ago

Question

Exposure to SQL desirable but not required

Answered: 1 week ago