IRECSQRT - Inverse of Recurrence Problem With a Square Root
Given this recurrence formula (be careful, it's in inverse form):
Given n (0 ≤ n < 264) and m (0 < m < 264), your task is to compute an modulo m.
It's guaranteed that an is always an integer.
Input
First line containing an integer T (0 < T ≤ 5×104), than T cases follow.
For each test case there are two integers n and m, written in one line, separated by a space.
Output
For each test case, output the required answer: an modulo m.
Example
Input: 10 0 10 1 10 2 10 3 10 10 10 100 100 1000 1000 10000 10000 100000 100000 9876543210123456789 1234567890987654321 Output: 1 2 5 5 5 51 251 6251 6251 657422418465782775
Time limit ~7x My program speed: Click here to see my submission history and time record for this problem
hide comments
Federico Lebrón:
2013-05-06 03:50:37
I liked this problem, thank you :) |
|
Ivan Hendrajaya:
2013-05-04 20:42:04
@Tjandra: Thanks, take a long time for me to solve this problem. For now C++ is my main programming language, so I try to solve this problem with highly (not fully) optimized C++ code. I think it would be better if the number of test cases is not that much. :) |
|
(Tjandra Satria Gunawan)(曾毅昆):
2013-04-28 10:17:35
@Ivan Hendrajaya: wow! superb solution... heavily optimized code written in C family ;-) I've been waiting that for a long time, finally it come.. thanks and congratulations, I hope you enjoy this problem.. :-D Last edit: 2013-04-28 11:09:18 |
|
Andy:
2013-04-17 20:21:00
why am I getting NZEC?
|
|
Shubham Depp Bansal:
2013-03-23 06:22:05
recursion limit is too much in python. why?
|
|
Michael Kharitonov:
2013-03-22 16:43:30
Insidious author chose the bounds of m to make C solution more complicated. Last edit: 2013-03-22 20:23:06 |
|
(Tjandra Satria Gunawan)(曾毅昆):
2013-03-19 16:14:53
seems that I pass that ONMIPA selection test 2013 (university level) :-D so start from tomorrow (20 March 2013) I'll be unavailable on SPOJ due to preparation on Regional Math Olympiad (ONMIPA regional level) until 11 April 2013, Sorry for inconvenience. Last edit: 2013-03-19 18:14:07 |
|
(Tjandra Satria Gunawan)(曾毅昆):
2013-03-16 09:13:34
You can challenge yourself to solve this problem using C language, if you feel you solve this problem easily :-)
|
|
Nipun Poddar:
2013-03-15 11:57:19
thanks Last edit: 2013-03-15 14:59:28 |
|
Francky:
2013-03-15 08:45:52
Cool, 120B of python code.
|
Added by: | Tjandra Satria Gunawan |
Date: | 2013-03-14 |
Time limit: | 13s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | ONMIPA sel 2013 |