Submit | All submissions | Best solutions | Back to list |
SNGLOOP1 - Easiest Loop 1 |
Ileana D'Cruz is taking programming classes but she is having problem in understanding while loops. She is working on following set of instructions -
INTEGER I = 0, S, U = 1010;
WHILE (I < U) {
S = (3 * S) + (5 * I);
I = I + 1;
}
Let Sk be the value assigned to INTEGER S for the iteration I = (k + 1) and n, m, p be positive integers such that m > n. Ileana knows the values of n and m but she forgot the initial value of S. She is trying to find the unit digit of p. Any initial value of S may be used. She also knows the following equality -
(2 * n + 3) * (p - 1) + (4 / 5) * [(p * Sn) - Sm] = 2 * (m - n)
Input
First line of input is T (total number of test cases). Each of next T lines contains two integers n and m.
Output
Print unit digit of p (p % 10) for each test case in separated lines.
Example
Input: 1 2 3 Output: 3
Constraints
T < 10001
Explanation
Let S = 2
S0 = 6
S1 = 23
S2 = 79
S3 = 252
Now solving the equation gives p = 3.
Added by: | AvmnuSng |
Date: | 2014-06-14 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | Abhimanyu Singh My Problems |
hide comments
|
|||||||
2014-06-17 22:56:54 AvmnuSng
@Jayesh Lata : It's never gonna work... why don't you think of something else, because it costs O(n) causing TLE |
|||||||
2014-06-17 18:52:44 Jayesh Lata
@Abhimanyu Singh: Can you look into my submission 11776749? I think it should work! |
|||||||
2014-06-17 18:20:59 Pushkar Protik Goswami
Enjoyed solving the problem! :) |
|||||||
2014-06-17 18:20:59 AvmnuSng
@Valar Morghulis : give a second thought to your solution. Last edit: 2014-06-21 00:23:08 |
|||||||
2014-06-17 18:20:59 Rishav Goyal
Cool problem.! |
|||||||
2014-06-17 18:20:59 CrazyCoder
please can anyone post some test cases ! |
|||||||
2014-06-17 18:20:59 Valar Morghulis
Hi ABhimanyu, Can you check my submission 11770233 ? It is giving me WA. I think I have solved correctly. |
|||||||
2014-06-17 18:20:59 AvmnuSng
@mitch : yup, I placed it to "none".... |
|||||||
2014-06-17 18:20:59 Francky
It's a bad spoj feature. When psetter place the problem to none, all comments are deleted, then when back to classical, comments are lost. You can edit the problem without put it back to none, so comments can stay 'alive'. (edit) Mitch yet answered that... == I had an accident last week (shoulder). I will be less present for some months. == Jacob Platcha is a new EB member, with Mitch they will do a great job. Many thanks for them. Last edit: 2014-06-16 10:17:55 |
|||||||
2014-06-17 18:20:59 Mitch Schwartz
@Abhimanyu Singh: Did you change the problem placement to "none" when editing? Doing that deletes all comments. It's a known bug. |