MODBERN - Modular Bernoulli
Bernoulli numbers are of great interest in mathematics and in computational sciences. They are rationnal numbers, our interest will be the numerator of the reduced fraction. Ada Lovelace is sometimes credited as the first programmer ; her interest was on Bernoulli numbers. You have less than two years before the 200th birthday of Ada, here is a good place to improve your skills.
The input contains several lines, you don't have to process all, it may be hard, only all first ones you are able to, in the given time. Each line contains two integers : N, and P a prime number.
For each line you will process, print numerator(BN). As the answer could not fit in a 64-bit container, just output your answer modulo P, lying in [0...P[.
Input: 2 5 5 7 10 13 12 23 [...] some more lines
Output: 1 0 5 22 [...] as many as you can.
For the fourth case, B12= (-691)/2730, and (-691) mod 23 = 22.
1 < N <= 10000 2 < P <= 30000, a prime number
Input contains uniform distribution. The challenge is to be the fastest, constraints allow everybody to get some points. There are 100000 lines, one point per case. If you can process all 10^5 lines, your score is 10^6/time. Have fun ;-)