Submit | All submissions | Best solutions | Back to list |
LOGFIB - Fibonacci numbers |
Let's define:
F(0)=0, F(1)=1.
F(j)=F(j-1)+F(j-2), for j>1
P(0)=0, P(1)=1, P(2)=2
P(j)=P(j-1)+2P(j-3), for j>2
Given an integer X and M, calculate the remainder of F(X) and P(X) after dividing them by the modulus M.
Input
First line: positive integer T - numer of test cases, T<20000.
Next T lines contain 2 integers each: Xi, and Mi.
Data constraints:
0 < Xi < +260
2 < Mi < +230
Output
For each of test cases, output the numbers F(Xi) mod Mi and P(Xi) mod Mi separated by a single space - one line per test case.
Example
Input: 6 1 23 4 56 7 89 123 456 7890 123 123456789012 34567890 Output: 1 1 3 4 13 20 2 204 55 103 29441184 24923102
Added by: | Robert Rychcicki |
Date: | 2009-01-10 |
Time limit: | 1.572s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | C-CLANG C NCSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG C99 JAVA JULIA PYTHON PYPY3 PYTHON3 SWIFT |