DIVFACT2 - Divisors of factorial (medium)
Factorial numbers are getting big very soon, you'll have to compute the number of divisors of such highly composite numbers.
Input
The first line contains an integer T, the number of test cases. On the next T lines, you will be given two integers N and M.
Output
Output T lines, one for each test case, with the number of divisors of the factorial of N. Since the answer can get very big, output it modulo M.
Example
Input: 3 2 1000 3 11 4 5 Output: 2 4 3
Constraints
0 < T < 512 1 < N < 10^8 1 < M < 10^9
For N, M : uniform random input in the range. One input file.
Information
Time limit is sqrt(T_good.py × T_bad.c). It implies that you can solve it with some interpreted languages with correct algorithm without any optis, but will get TLE with fast languages and non optimal algorithm. Good luck and have fun ;-)
(Edit 2017-02-11 : TL updated ; compiler changes)
hide comments
sankalp_7:
2021-07-09 11:45:07
I would be very grateful to the author, if he can tell the mistake in my code.
|
|
pratham_1:
2017-07-16 11:53:18
Any hints for this problem ?? i give up |
|
surya2196:
2016-04-03 16:22:52
@francky can you plese provide some test case
|
|
shivucoder55:
2016-03-18 21:05:25
I solved by precomputing all prime numbers less than 10^8 then determining no. of divisors but still getting TLE ....
|
|
shikhar jindal:
2016-03-17 17:26:38
not getting any idea how to solve this :( ...what other concepts are needed along with the lagrange's theorem..thanks in advance :)
|
|
Maroof:
2015-06-08 12:17:34
Why this problem isn't showing on the list of solved problems? .. BTW awesome problem. Learnt a lot of things to optimize the code :)
|
|
Sayak Haldar:
2015-02-11 14:08:11
Francky, would I get an AC if I precompute all the prime nos less than 10^8 then use (n)1/2(logn) per query?
|
|
Francky:
2015-01-30 17:41:09
Now there's DIVFACT4, it's time to move this one to tutorial, as almost every submission got AC with both (DF2, DF3) without any change.
|
|
rohith:
2015-01-24 12:19:43
@Francky my code works absolutely fine but still WA
|
|
[Lakshman]:
2015-01-19 07:58:25
Enjoying this!! Getting closer to abdou_93 Trying for first place..........Taken first place!!!
|
Added by: | Francky |
Date: | 2015-01-17 |
Time limit: | 5.5s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 JS-MONKEY |
Resource: | DIVFACT |