Home (/) » Compete (/contests/) » February Challenge 2018 (/FEB18?order=desc&sortBy=successful_submissions) » Broken Clock
Tweet
(https://twitter.com
Like Share 16 people like this. Be the first of your friends.
/share)
One endpoint of the minute hand is always located at the clock center; the other
endpoint is initially located at the point (0, l). One second later, Chef observes that this
endpoint is at distance d above the x-axis, i.e. the y-coordinate of this endpoint is equal
to d.
Chef is curious about where the minute hand will be (specifically, its y-coordinate) after t
seconds. Because t can be very large, Chef can't wait for that moment. Please help him!
Input
The first line of the input contains a single integer T denoting the number of test
cases. The description of T test cases follows.
The first and only line of each test case contains three space-separated integers l, d
and t.
Output
We can prove that for the given constraints, the y-coordinate of the end of the minute
hand can always be written as a rational number p / q, where gcd(p, q) = gcd(q, 109 + 7)
= 1. Let's denote the modular inverse of q (it's guaranteed that the modular inverse
exists and is unique) by r.
For each test case, print a single line containing one number (p · r) modulo 109 + 7.
Constraints
1 ≤ T ≤ 105
1 ≤ d < l ≤ 109
1 ≤ t ≤ 1018
Subtasks
Subtask #1 (5 points): t ≤ 3
Example
Input:
3
4 2 1
4 2 2
4 2 3
Output:
2
1000000005
1000000003
Explanation
Example case 1:
Example case 2:
Example case 3:
Comments
© 2009 Directi Group (http://directi.com). All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs (http://www.sphere-research.com)
In order to report copyright violations of any kind, send in an email to copyright@codechef.com (mailto:copyright@codechef.com)
(http://directi.com)
FAQ's (https://www.codechef.com/wiki/faq)
Initiatives
3 of 3 08/02/18, 9:32 PM