Submit | All submissions | Best solutions | Back to list |
ADAROBOT - Ada and CAPTCHA |
Ada the Ladybug just got an innovative idea (which might be a rival of captcha): She made following function - F(a)=least significant 1-bit of a (indexed from 1). She also made following recursive function T(N) = F(N*(N-1))3 + T(N-2), where T(0) = 0, T(1) = 0.
Her idea is following- Instead of asking for captcha, she uses an opposite method: She gives you even N and you have to answer T(N) - if your answer is correct, then you are definitely a robot and you won't be let in.
As her good friend she asked you to program a checker for her.
Input
The input begins with an integer 1 ≤ Q ≤ 106 , number of queries.
The next Q lines contains an even integer: 2 ≤ N ≤ 2*108
Output
For each query, print T(N)
Example Input
5 8 4 2 20 1000
Example Output
107 35 8 310 23988
Little explanation
F(2)=2 F(12)=3 F(30)=2 F(56)=4 F(90)=2 F(132)=3 F(182)=2 F(240)=5 F(306)=2 F(380)=3
Added by: | Morass |
Date: | 2017-03-14 |
Time limit: | 0.800s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
hide comments
|
||||||
2017-03-28 07:15:18
Hey. I am not able to understand the function F(n). Can anyone explain it to me taking a few examples ? |
||||||
2017-03-24 19:03:29
@morass why my solution is taking so much time is not it optimal |
||||||
2017-03-19 21:49:59
@anmol23: It is not - an example is map, which works in O(log(N)) time **And use some "faster" io Last edit: 2017-03-20 10:48:39 |
||||||
2017-03-19 19:05:55
@morass I think my solution is linear. Can you see and tell how to improve it |
||||||
2017-03-19 07:19:35
@anmol23: Hello. Using solution linear (or better) with "N" as per problem (not just as per test-case) |
||||||
2017-03-18 12:41:31
How can I avoid TLE? |
||||||
2017-03-14 07:39:12
@mahmud2690 / @[Rampage] Blue.Mary: Good day to you .. . I'm really sorry, there shall be "2*10^8" in statement :( sorry for the inconvenience - I've repaired the statement |
||||||
2017-03-14 07:28:16
It seems there are cases N < 0 or N > 100000000 |
||||||
2017-03-14 02:53:09 [Rampage] Blue.Mary
Are you sure your test cases are right? |